Skip to content

Commit

Permalink
#119: Add "energy" tag to newly crafted capacitors and in creative inv
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucraft committed Jan 19, 2025
1 parent f117ac1 commit 32e7e5c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.threetag.palladium.item;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

public abstract class EnergyItem extends Item {

Expand All @@ -26,4 +28,10 @@ public int getEnergyMaxOutput(ItemStack stack) {
return maxOutput;
}

@Override
public void onCraftedBy(ItemStack stack, Level level, Player player) {
if (!stack.hasTag() || !stack.getOrCreateTag().contains("energy")) {
stack.getOrCreateTag().putInt("energy", 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public RenderLayerContainer getRenderLayerContainer() {
return this.renderLayerContainer;
}

public ItemStack getEmptyInstance() {
var filled = this.getDefaultInstance();
filled.getOrCreateTag().putInt("energy", 0);
return filled;
}

public ItemStack getFullyChargedInstance() {
var filled = this.getDefaultInstance();
filled.getOrCreateTag().putInt("energy", this.getEnergyCapacity(filled));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,26 @@ public static void init() {
SUIT_STAND.get(),
LEAD_CIRCUIT.get(),
QUARTZ_CIRCUIT.get(),
VIBRANIUM_CIRCUIT.get(),
LEAD_FLUX_CAPACITOR.get(),
LEAD_BLOCK.get(),
QUARTZ_FLUX_CAPACITOR.get(),
VIBRANIUM_FLUX_CAPACITOR.get(),
VIBRANIUM_WEAVE_BOOTS.get()
VIBRANIUM_CIRCUIT.get()
);

entries.add(
LEAD_FLUX_CAPACITOR.get().getEmptyInstance(),
QUARTZ_FLUX_CAPACITOR.get().getEmptyInstance(),
VIBRANIUM_FLUX_CAPACITOR.get().getEmptyInstance(),
VIBRANIUM_WEAVE_BOOTS.get().getDefaultInstance()
);
});

CreativeModeTabRegistry.addToTab(PalladiumCreativeModeTabs.TECHNOLOGY, entries -> {
entries.add(LEAD_CIRCUIT.get());
entries.add(QUARTZ_CIRCUIT.get());
entries.add(VIBRANIUM_CIRCUIT.get());
entries.add(LEAD_FLUX_CAPACITOR.get());
entries.add(LEAD_FLUX_CAPACITOR.get().getEmptyInstance());
entries.add(LEAD_FLUX_CAPACITOR.get().getFullyChargedInstance());
entries.add(QUARTZ_FLUX_CAPACITOR.get());
entries.add(QUARTZ_FLUX_CAPACITOR.get().getEmptyInstance());
entries.add(QUARTZ_FLUX_CAPACITOR.get().getFullyChargedInstance());
entries.add(VIBRANIUM_FLUX_CAPACITOR.get());
entries.add(VIBRANIUM_FLUX_CAPACITOR.get().getEmptyInstance());
entries.add(VIBRANIUM_FLUX_CAPACITOR.get().getFullyChargedInstance());
});

Expand Down

0 comments on commit 32e7e5c

Please sign in to comment.