diff --git a/src/main/java/com/direwolf20/mininggadgets/common/capabilities/CapabilityEnergyProvider.java b/src/main/java/com/direwolf20/mininggadgets/common/capabilities/CapabilityEnergyProvider.java index 1abbb079..93f477ca 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/capabilities/CapabilityEnergyProvider.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/capabilities/CapabilityEnergyProvider.java @@ -4,9 +4,9 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.core.Direction; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.common.util.LazyOptional; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import javax.annotation.Nonnull; @@ -25,6 +25,6 @@ public CapabilityEnergyProvider(ItemStack stack, int energyCapacity) { @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction side) { - return cap == CapabilityEnergy.ENERGY ? capability.cast() : LazyOptional.empty(); + return cap == ForgeCapabilities.ENERGY ? capability.cast() : LazyOptional.empty(); } } diff --git a/src/main/java/com/direwolf20/mininggadgets/common/containers/ModificationTableCommands.java b/src/main/java/com/direwolf20/mininggadgets/common/containers/ModificationTableCommands.java index 990f848f..720e29af 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/containers/ModificationTableCommands.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/containers/ModificationTableCommands.java @@ -11,7 +11,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; -import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import java.util.List; @@ -51,8 +51,14 @@ public static boolean insertButton(ModificationTableContainer container, ItemSta // Did we just insert a battery upgrade? if(card.getBaseName().equals(Upgrade.BATTERY_1.getBaseName())) { UpgradeBatteryLevels.getBatteryByLevel(card.getTier()).ifPresent(power -> { - laser.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> ((EnergisedItem) e).updatedMaxEnergy(power.getPower())); + laser.getCapability(ForgeCapabilities.ENERGY).ifPresent(e -> { + ((EnergisedItem) e).updatedMaxEnergy(power.getPower()); + if (card.getTier() == Upgrade.BATTERY_CREATIVE.getTier()) { + e.receiveEnergy(e.getMaxEnergyStored() - e.getEnergyStored(), false); + } + }); }); + MiningProperties.setBatteryTier(laser, card.getTier()); } return true; @@ -91,8 +97,10 @@ public static void extractButton(ModificationTableContainer container, ServerPla MiningProperties.setBeamMaxRange(laser, UpgradeTools.getMaxBeamRange(0)); } - if (upgrade.getBaseName().equals(Upgrade.BATTERY_1.getBaseName())) - laser.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> ((EnergisedItem) e).updatedMaxEnergy(UpgradeBatteryLevels.BATTERY.getPower())); + if (upgrade.getBaseName().equals(Upgrade.BATTERY_1.getBaseName())) { + MiningProperties.setBatteryTier(laser, 0); + laser.getCapability(ForgeCapabilities.ENERGY).ifPresent(e -> ((EnergisedItem) e).updatedMaxEnergy(UpgradeBatteryLevels.BATTERY.getPower())); + } }); } } diff --git a/src/main/java/com/direwolf20/mininggadgets/common/data/GeneratorLanguage.java b/src/main/java/com/direwolf20/mininggadgets/common/data/GeneratorLanguage.java index 75bb0380..abecf8e5 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/data/GeneratorLanguage.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/data/GeneratorLanguage.java @@ -45,6 +45,7 @@ protected void addTranslations() { addItem(ModItems.BATTERY_1, "Upgrade: Battery, Tier 1"); addItem(ModItems.BATTERY_2, "Upgrade: Battery, Tier 2"); addItem(ModItems.BATTERY_3, "Upgrade: Battery, Tier 3"); + addItem(ModItems.BATTERY_CREATIVE, "Upgrade: Creative Battery"); // Upgrade tooltips :D add("tooltop.mininggadgets.empty", "Used to craft other upgrades"); diff --git a/src/main/java/com/direwolf20/mininggadgets/common/items/EnergisedItem.java b/src/main/java/com/direwolf20/mininggadgets/common/items/EnergisedItem.java index 9be74bfd..7761ee1b 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/items/EnergisedItem.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/items/EnergisedItem.java @@ -23,6 +23,7 @@ private static int getMaxCapacity(ItemStack stack, int capacity) { public void updatedMaxEnergy(int max) { stack.getOrCreateTag().putInt("max_energy", max); this.capacity = max; + this.energy = Math.min(max, this.energy); // Ensure the current stored energy is up to date with the new max. this.receiveEnergy(1, false); diff --git a/src/main/java/com/direwolf20/mininggadgets/common/items/MiningGadget.java b/src/main/java/com/direwolf20/mininggadgets/common/items/MiningGadget.java index 823b7574..4b1fabad 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/items/MiningGadget.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/items/MiningGadget.java @@ -54,8 +54,8 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.event.world.BlockEvent; @@ -88,7 +88,10 @@ public int getMaxDamage(ItemStack stack) { @Override public boolean isBarVisible(ItemStack stack) { - IEnergyStorage energy = stack.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); + if (MiningProperties.getBatteryTier(stack) == Upgrade.BATTERY_CREATIVE.getTier()) + return false; + + IEnergyStorage energy = stack.getCapability(ForgeCapabilities.ENERGY, null).orElse(null); return (energy.getEnergyStored() < energy.getMaxEnergyStored()); } @@ -100,14 +103,20 @@ public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundT @Override public int getBarWidth(ItemStack stack) { - return stack.getCapability(CapabilityEnergy.ENERGY, null) + if (MiningProperties.getBatteryTier(stack) == Upgrade.BATTERY_CREATIVE.getTier()) + return 13; + + return stack.getCapability(ForgeCapabilities.ENERGY, null) .map(e -> Math.min(13 * e.getEnergyStored() / e.getMaxEnergyStored(), 13)) .orElse(0); } @Override public int getBarColor(ItemStack stack) { - return stack.getCapability(CapabilityEnergy.ENERGY) + if (MiningProperties.getBatteryTier(stack) == Upgrade.BATTERY_CREATIVE.getTier()) + return Mth.color(0, 1, 0); + + return stack.getCapability(ForgeCapabilities.ENERGY) .map(e -> Mth.hsvToRgb(Math.max(0.0F, (float) e.getEnergyStored() / (float) e.getMaxEnergyStored()) / 3.0F, 1.0F, 1.0F)) .orElse(super.getBarColor(stack)); } @@ -141,7 +150,7 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List { TranslatableComponent energyText = !sneakPressed ? new TranslatableComponent("mininggadgets.gadget.energy", MagicHelpers.tidyValue(energy.getEnergyStored()), MagicHelpers.tidyValue(energy.getMaxEnergyStored())) @@ -169,7 +178,10 @@ public static void changeRange(ItemStack tool) { } public static boolean canMine(ItemStack tool) { - IEnergyStorage energy = tool.getCapability(CapabilityEnergy.ENERGY, null).orElse(null); + if (MiningProperties.getBatteryTier(tool) == Upgrade.BATTERY_CREATIVE.getTier()) + return true; + + IEnergyStorage energy = tool.getCapability(ForgeCapabilities.ENERGY, null).orElse(null); int cost = getEnergyCost(tool); if (MiningProperties.getRange(tool) == 3) @@ -443,7 +455,7 @@ else if (g > 0 && b == 1) else*/ durability = durability - 1; if (durability <= 0) { - stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.receiveEnergy(getEnergyCost(stack) * -1, false)); + stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(e -> e.receiveEnergy(getEnergyCost(stack) * -1, false)); if (MiningProperties.getPrecisionMode(stack)) { MiningProperties.setCanMine(stack, false); player.stopUsingItem(); @@ -472,16 +484,19 @@ else if (g > 0 && b == 1) pos = lookingAt.getBlockPos().relative(side).relative(right); if (world.getMaxLocalRawBrightness(pos) <= 7 && world.getBlockState(pos).getMaterial() == Material.AIR) { - int energy = stack.getCapability(CapabilityEnergy.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0); + int energy = stack.getCapability(ForgeCapabilities.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0); if (energy > Config.UPGRADECOST_LIGHT.get()) { world.setBlockAndUpdate(pos, ModBlocks.MINERS_LIGHT.get().defaultBlockState()); - stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.receiveEnergy((Config.UPGRADECOST_LIGHT.get() * -1), false)); + stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(e -> e.receiveEnergy((Config.UPGRADECOST_LIGHT.get() * -1), false)); } } } } public static int getEnergyCost(ItemStack stack) { + if (MiningProperties.getBatteryTier(stack) == Upgrade.BATTERY_CREATIVE.getTier()) + return 0; + int cost = Config.MININGGADGET_BASECOST.get(); List upgrades = UpgradeTools.getActiveUpgrades(stack); if (upgrades.isEmpty()) diff --git a/src/main/java/com/direwolf20/mininggadgets/common/items/ModItems.java b/src/main/java/com/direwolf20/mininggadgets/common/items/ModItems.java index d1e1a443..9cb1fb3b 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/items/ModItems.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/items/ModItems.java @@ -46,6 +46,7 @@ public class ModItems { public static final RegistryObject BATTERY_1 = UPGRADE_ITEMS.register("upgrade_battery_1", () -> Upgrade.BATTERY_1.getCard()); public static final RegistryObject BATTERY_2 = UPGRADE_ITEMS.register("upgrade_battery_2", () -> Upgrade.BATTERY_2.getCard()); public static final RegistryObject BATTERY_3 = UPGRADE_ITEMS.register("upgrade_battery_3", () -> Upgrade.BATTERY_3.getCard()); + public static final RegistryObject BATTERY_CREATIVE = UPGRADE_ITEMS.register("upgrade_battery_creative", () -> Upgrade.BATTERY_CREATIVE.getCard()); public static final RegistryObject EFFICIENCY_1 = UPGRADE_ITEMS.register("upgrade_efficiency_1", () -> Upgrade.EFFICIENCY_1.getCard()); public static final RegistryObject EFFICIENCY_2 = UPGRADE_ITEMS.register("upgrade_efficiency_2", () -> Upgrade.EFFICIENCY_2.getCard()); public static final RegistryObject EFFICIENCY_3 = UPGRADE_ITEMS.register("upgrade_efficiency_3", () -> Upgrade.EFFICIENCY_3.getCard()); diff --git a/src/main/java/com/direwolf20/mininggadgets/common/items/gadget/MiningProperties.java b/src/main/java/com/direwolf20/mininggadgets/common/items/gadget/MiningProperties.java index 92340c55..a53667b0 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/items/gadget/MiningProperties.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/items/gadget/MiningProperties.java @@ -29,6 +29,7 @@ private MiningProperties() {} private static final String PRECISION_MODE = "precisionMode"; private static final String VOLUME = "volume"; private static final String FREEZE_PARTICLE_DELAY = "freeze_particle_delay"; + private static final String KEY_BATTERY_TIER = "battery_tier"; public static final String KEY_FILTERS = "filters"; public static final String COLOR_RED = "colorRed"; @@ -169,6 +170,16 @@ public static int getFreezeDelay(ItemStack gadget) { return !compound.contains(FREEZE_PARTICLE_DELAY) ? setFreezeDelay(gadget, 0) : compound.getInt(FREEZE_PARTICLE_DELAY); } + public static int setBatteryTier(ItemStack gadget, int tier) { + gadget.getOrCreateTag().putInt(KEY_BATTERY_TIER, tier); + return tier; + } + + public static int getBatteryTier(ItemStack gadget) { + CompoundTag compound = gadget.getOrCreateTag(); + return !compound.contains(KEY_BATTERY_TIER) ? setBatteryTier(gadget, 0) : compound.getInt(KEY_BATTERY_TIER); + } + /** * So this is a bit fun, because we only need the items in our list we're ditching half the data * that the `Items` actually contains. diff --git a/src/main/java/com/direwolf20/mininggadgets/common/items/upgrade/Upgrade.java b/src/main/java/com/direwolf20/mininggadgets/common/items/upgrade/Upgrade.java index 9f2b2661..11281fd7 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/items/upgrade/Upgrade.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/items/upgrade/Upgrade.java @@ -31,7 +31,7 @@ public enum Upgrade { THREE_BY_THREE("three_by_three", () -> 0, false), LIGHT_PLACER("light_placer", () -> 0), // applied at operation based on config. this isn't ideal // PAVER("paver", () -> 10), - + // Tiered FORTUNE_1("fortune_1", 1, () -> Config.UPGRADECOST_FORTUNE1.get(), true), FORTUNE_2("fortune_2", 2, () -> Config.UPGRADECOST_FORTUNE2.get(), true), @@ -40,6 +40,7 @@ public enum Upgrade { BATTERY_1("battery_1", 1, () -> 0), BATTERY_2("battery_2", 2, () -> 0), BATTERY_3("battery_3", 3, () -> 0), + BATTERY_CREATIVE("battery_CREATIVE", 4, () -> 0), RANGE_1("range_1", 1, () -> 0), RANGE_2("range_2", 2, () -> 0), diff --git a/src/main/java/com/direwolf20/mininggadgets/common/items/upgrade/UpgradeBatteryLevels.java b/src/main/java/com/direwolf20/mininggadgets/common/items/upgrade/UpgradeBatteryLevels.java index d20335d1..4ed57c20 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/items/upgrade/UpgradeBatteryLevels.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/items/upgrade/UpgradeBatteryLevels.java @@ -15,7 +15,8 @@ public enum UpgradeBatteryLevels { BATTERY(0, Config.MININGGADGET_MAXPOWER.get()), BATTERY_1(1, Config.UPGRADECOST_BATTERY1.get()), BATTERY_2(2, Config.UPGRADECOST_BATTERY2.get()), - BATTERY_3(3, Config.UPGRADECOST_BATTERY3.get()); + BATTERY_3(3, Config.UPGRADECOST_BATTERY3.get()), + BATTERY_CREATIVE(4, Integer.MAX_VALUE); private int level; private int power; diff --git a/src/main/java/com/direwolf20/mininggadgets/common/tiles/RenderBlockTileEntity.java b/src/main/java/com/direwolf20/mininggadgets/common/tiles/RenderBlockTileEntity.java index aac0515c..1672029e 100644 --- a/src/main/java/com/direwolf20/mininggadgets/common/tiles/RenderBlockTileEntity.java +++ b/src/main/java/com/direwolf20/mininggadgets/common/tiles/RenderBlockTileEntity.java @@ -32,7 +32,7 @@ import net.minecraft.world.level.material.Fluids; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.world.BlockEvent; @@ -195,7 +195,7 @@ public void setDurability(int dur, ItemStack stack) { private void freeze(ItemStack stack) { int freezeCost = Config.UPGRADECOST_FREEZE.get() * -1; - int energy = stack.getCapability(CapabilityEnergy.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0); + int energy = stack.getCapability(ForgeCapabilities.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0); if (energy == 0) { return; @@ -220,7 +220,7 @@ private int replaceBlockWithAlternative(Level world, BlockPos pos, BlockState st return 0; } - stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.receiveEnergy(costOfOperation, false)); + stack.getCapability(ForgeCapabilities.ENERGY).ifPresent(e -> e.receiveEnergy(costOfOperation, false)); // If the block is just water logged, remove the fluid BlockState blockState = world.getBlockState(pos); diff --git a/src/main/resources/assets/mininggadgets/textures/item/upgrade_battery_creative.png b/src/main/resources/assets/mininggadgets/textures/item/upgrade_battery_creative.png new file mode 100644 index 00000000..0787001c Binary files /dev/null and b/src/main/resources/assets/mininggadgets/textures/item/upgrade_battery_creative.png differ