diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index 35e1348da..ccc8edb10 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -115,7 +115,7 @@ e2c81adfe240117fa0ce2e3dfcfd04f4e1034153 assets/actuallyadditions/blockstates/wh 3670535838b4c26d01afe7ee4807c53a6cbaba12 assets/actuallyadditions/blockstates/white_wall_block.json 78e89628e3c6e891f2994b2a1794672f69826516 assets/actuallyadditions/blockstates/wood_casing_block.json 207adf3d139369e983100a6002f6f77d36d40916 assets/actuallyadditions/blockstates/xp_solidifier_block.json -d8850d66bfac1fdc09b7872f5602a4325cd82ba9 assets/actuallyadditions/lang/en_us.json +df3dba5195138437f46df032562fdca2cf335bfa assets/actuallyadditions/lang/en_us.json 8ce3f2af3288773fb581a3668c2cb90b64c9ee2f assets/actuallyadditions/models/block/advanced_item_laser_relay_block.json de74eda6290d47ef2b26961693e537d7b8795a06 assets/actuallyadditions/models/block/atomic_reconstructor_block.json 16a76926a07fc8fa10e4a3949d15ad2ca6920bb8 assets/actuallyadditions/models/block/battery_box_block.json diff --git a/src/generated/resources/assets/actuallyadditions/lang/en_us.json b/src/generated/resources/assets/actuallyadditions/lang/en_us.json index 3a282fdb4..9b6a71b2e 100644 --- a/src/generated/resources/assets/actuallyadditions/lang/en_us.json +++ b/src/generated/resources/assets/actuallyadditions/lang/en_us.json @@ -1,5 +1,8 @@ { "actuallyadditions.storage.crystal-flux": "%s/%s Crystal Flux", + "actuallyadditions.tooltip.battery.charge-help": "Sneak-right-click to toggle", + "actuallyadditions.tooltip.battery.charging": "Charging other item in inventory", + "actuallyadditions.tooltip.battery.not-charging": "Not charging other items in inventory", "actuallyadditions.tooltip.booklet.manual.one": "Or \"Booklet\", if you will", "actuallyadditions.tooltip.booklet.manual.three": "Use while holding to open.", "actuallyadditions.tooltip.booklet.manual.two": "This book guides you through all of the feature Actually Additions has to over.", @@ -135,7 +138,7 @@ "item.actuallyadditions.basic_coil": "Basic Coil", "item.actuallyadditions.bats_wing": "Bat's Wing", "item.actuallyadditions.black_crystal_shard": "Black Crystal Shard", - "item.actuallyadditions.black_quartz": "Black Quarts", + "item.actuallyadditions.black_quartz": "Black Quartz", "item.actuallyadditions.blue_crystal_shard": "Blue Crystal Shard", "item.actuallyadditions.booklet": "Actually Additions Manual", "item.actuallyadditions.bowl_of_water": "Bowl of Water", @@ -290,7 +293,7 @@ "item.actuallyadditions.phantom_connector": "Phantom Connector", "item.actuallyadditions.player_probe": "Player Probe", "item.actuallyadditions.quadruple_battery": "Quadruple Battery", - "item.actuallyadditions.quartz_aiot": "Quartz AIOT", + "item.actuallyadditions.quartz_aiot": "Black Quartz AIOT", "item.actuallyadditions.quartz_axe": "Quartz Axe", "item.actuallyadditions.quartz_boots": "Quartz Boots", "item.actuallyadditions.quartz_chest": "Quartz Chestplate", diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/capability/CrystalFluxProvider.java b/src/main/java/de/ellpeck/actuallyadditions/common/capability/CrystalFluxProvider.java index 8e50edefe..156cfe54f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/capability/CrystalFluxProvider.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/capability/CrystalFluxProvider.java @@ -14,11 +14,20 @@ import javax.annotation.Nullable; public class CrystalFluxProvider implements ICapabilityProvider { private ItemStack stack; private int energy; - private LazyOptional capability = LazyOptional.of(() -> new CrystalFluxStorage(stack, energy)); + private int transfer; + + private LazyOptional capability = LazyOptional.of(() -> new CrystalFluxStorage(stack, energy, transfer)); public CrystalFluxProvider(ItemStack stack, int energy) { this.stack = stack; this.energy = energy; + this.transfer = Integer.MAX_VALUE; + } + + public CrystalFluxProvider(ItemStack stack, int energy, int transfer) { + this.stack = stack; + this.energy = energy; + this.transfer = transfer; } @Nonnull diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/capability/CrystalFluxStorage.java b/src/main/java/de/ellpeck/actuallyadditions/common/capability/CrystalFluxStorage.java index 7bb27849b..9850fcdc2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/capability/CrystalFluxStorage.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/capability/CrystalFluxStorage.java @@ -12,8 +12,8 @@ public class CrystalFluxStorage extends EnergyStorage { public static final String NBT_TAG = "crystal-flux"; private final ItemStack stack; - public CrystalFluxStorage(ItemStack stack, int capacity) { - super(capacity, Integer.MAX_VALUE, Integer.MAX_VALUE); + public CrystalFluxStorage(ItemStack stack, int capacity, int transfer) { + super(capacity, transfer, transfer); this.stack = stack; diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItems.java b/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItems.java index fdbc30cea..b504d56e8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItems.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItems.java @@ -2,10 +2,7 @@ package de.ellpeck.actuallyadditions.common.items; import com.google.common.collect.ImmutableSet; import de.ellpeck.actuallyadditions.common.ActuallyAdditions; -import de.ellpeck.actuallyadditions.common.items.useables.AllInOneTool; -import de.ellpeck.actuallyadditions.common.items.useables.LeafBlowerItem; -import de.ellpeck.actuallyadditions.common.items.useables.ManualItem; -import de.ellpeck.actuallyadditions.common.items.useables.TeleportStaffItem; +import de.ellpeck.actuallyadditions.common.items.useables.*; import de.ellpeck.actuallyadditions.common.materials.ArmorMaterials; import de.ellpeck.actuallyadditions.common.materials.ToolMaterials; import net.minecraft.item.Item; @@ -107,11 +104,14 @@ public final class ActuallyItems { public static final RegistryObject LASER_WRENCH = ITEMS.register("laser_wrench", basicItem()); public static final RegistryObject TELEPORT_STAFF = ITEMS.register("teleport_staff", TeleportStaffItem::new); public static final RegistryObject WINGS_OF_THE_BATS = ITEMS.register("wings_of_the_bats", basicItem()); - public static final RegistryObject SINGLE_BATTERY = ITEMS.register("single_battery", basicItem()); - public static final RegistryObject DOUBLE_BATTERY = ITEMS.register("double_battery", basicItem()); - public static final RegistryObject TRIPLE_BATTERY = ITEMS.register("triple_battery", basicItem()); - public static final RegistryObject QUADRUPLE_BATTERY = ITEMS.register("quadruple_battery", basicItem()); - public static final RegistryObject QUINTUPLE_BATTERY = ITEMS.register("quintuple_battery", basicItem()); + + // Batteries + public static final RegistryObject SINGLE_BATTERY = ITEMS.register("single_battery", () -> new BatteryItem(() -> 200000, 1000)); + public static final RegistryObject DOUBLE_BATTERY = ITEMS.register("double_battery", () -> new BatteryItem(() -> 350000, 5000)); + public static final RegistryObject TRIPLE_BATTERY = ITEMS.register("triple_battery", () -> new BatteryItem(() -> 600000, 10000)); + public static final RegistryObject QUADRUPLE_BATTERY = ITEMS.register("quadruple_battery", () -> new BatteryItem(() -> 1000000, 30000)); + public static final RegistryObject QUINTUPLE_BATTERY = ITEMS.register("quintuple_battery", () -> new BatteryItem(() -> 2000000, 100000)); + public static final RegistryObject DRILL_MAIN = ITEMS.register("drill_light_blue", basicItem()); public static final RegistryObject DRILL_BLACK = ITEMS.register("drill_black", basicItem()); public static final RegistryObject DRILL_BLUE = ITEMS.register("drill_blue", basicItem()); diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/items/CrystalFluxItem.java b/src/main/java/de/ellpeck/actuallyadditions/common/items/CrystalFluxItem.java index 64bd013f1..d46bede05 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/items/CrystalFluxItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/items/CrystalFluxItem.java @@ -35,6 +35,7 @@ public abstract class CrystalFluxItem extends ActuallyItem { alt ? NumberFormat.getIntegerInstance().format(value) : Help.compressedValue(value); private final Supplier maxFlux; + private final int transfer; /** * We use a supplier here to allow for config values to be passed around so we are able to @@ -46,12 +47,24 @@ public abstract class CrystalFluxItem extends ActuallyItem { super(properties); this.maxFlux = maxFlux; + this.transfer = Integer.MAX_VALUE; + } + + /** + * Allows for granular control over the transfer rate + * @param maxFlux max energy this item can store + * @param transfer max transfer rate for energy + */ + public CrystalFluxItem(Properties properties, Supplier maxFlux, int transfer) { + super(properties); + this.maxFlux = maxFlux; + this.transfer = transfer; } @Nullable @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { - return new CrystalFluxProvider(stack, maxFlux.get()); + return new CrystalFluxProvider(stack, maxFlux.get(), this.transfer); } @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/items/IActivates.java b/src/main/java/de/ellpeck/actuallyadditions/common/items/IActivates.java new file mode 100644 index 000000000..10ca3c090 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/common/items/IActivates.java @@ -0,0 +1,19 @@ +package de.ellpeck.actuallyadditions.common.items; + +import net.minecraft.item.ItemStack; + +public interface IActivates { + String NBT_TAG = "is-enabled"; + + default boolean isEnabled(ItemStack stack) { + return stack.getOrCreateTag().getBoolean(NBT_TAG); + } + + default void toggle(ItemStack stack) { + stack.getOrCreateTag().putBoolean(NBT_TAG, !isEnabled(stack)); + } + + default void manualToggle(ItemStack stack, boolean enabled) { + stack.getOrCreateTag().putBoolean(NBT_TAG, enabled); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/BatteryItem.java b/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/BatteryItem.java new file mode 100644 index 000000000..fd1d6e4a0 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/BatteryItem.java @@ -0,0 +1,91 @@ +package de.ellpeck.actuallyadditions.common.items.useables; + +import de.ellpeck.actuallyadditions.common.items.CrystalFluxItem; +import de.ellpeck.actuallyadditions.common.items.IActivates; +import de.ellpeck.actuallyadditions.common.utilities.Help; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; +import net.minecraftforge.energy.CapabilityEnergy; + +import javax.annotation.Nullable; +import java.util.List; +import java.util.function.Supplier; + +public class BatteryItem extends CrystalFluxItem implements IActivates { + public BatteryItem(Supplier maxFlux, int transfer) { + super(baseProps().maxStackSize(1).setNoRepair().maxDamage(0), maxFlux, transfer); + } + + @Override + public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) { + if (world.isRemote || !(entity instanceof PlayerEntity) || !isEnabled(stack) || isSelected) { + return; + } + + // Don't run if we have no charge. Duh + if (stack.getCapability(CapabilityEnergy.ENERGY) + .map(e -> e.getEnergyStored() <= 0) + .orElse(true) + ) { + return; + } + + PlayerEntity player = (PlayerEntity) entity; + for(int i = 0; i < player.inventory.getSizeInventory(); i++) { + ItemStack slot = player.inventory.getStackInSlot(i); + + // We don't care for weirdo stackable charging items, nor the same item as is charging others. Duh + if (slot.isEmpty() || slot.getCount() != 1 || slot.equals(stack)) { + continue; + } + + slot.getCapability(CapabilityEnergy.ENERGY).ifPresent(energy -> { + // Don't keep charging if empty + if (energy.getEnergyStored() >= energy.getMaxEnergyStored()) { + return; + } + + // Find max power from the battery and use that to attempt to charge the other item + int maxExtractable = stack.getCapability(CapabilityEnergy.ENERGY).map(e -> e.extractEnergy(Integer.MAX_VALUE, true)).orElse(0); + int received = energy.receiveEnergy(maxExtractable, false); + + if (received > 0) { + stack.getCapability(CapabilityEnergy.ENERGY).ifPresent(e -> e.extractEnergy(received, false)); + } + }); + } + } + + @Override + public ActionResult onItemRightClick(World world, PlayerEntity player, Hand hand) { + if (!world.isRemote && player.isSneaking()) { + ItemStack heldItem = player.getHeldItem(hand); + + toggle(heldItem); + return ActionResult.resultSuccess(heldItem); + } + + return super.onItemRightClick(world, player, hand); + } + + @Override + public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { + super.addInformation(stack, worldIn, tooltip, flagIn); + + boolean enabled = isEnabled(stack); + tooltip.add(Help.trans(String.format("tooltip.battery.%s", enabled ? "charging" : "not-charging")).mergeStyle(enabled ? TextFormatting.GREEN : TextFormatting.GRAY)); + tooltip.add(Help.trans("tooltip.battery.charge-help")); + } + + @Override + public boolean hasEffect(ItemStack stack) { + return isEnabled(stack); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/package-info.java b/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/package-info.java new file mode 100644 index 000000000..a3cefbdd5 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +package de.ellpeck.actuallyadditions.common.items.useables; + +import mcp.MethodsReturnNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java b/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java index c574dd298..c10b1dd16 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java @@ -322,6 +322,11 @@ public class GeneratorLanguage extends LanguageProvider { addPrefixed("tooltip.booklet.manual.two", "This book guides you through all of the feature Actually Additions has to over."); addPrefixed("tooltip.booklet.manual.three", "Use while holding to open."); + // Battery + addPrefixed("tooltip.battery.not-charging", "Not charging other items in inventory"); + addPrefixed("tooltip.battery.charging", "Charging other item in inventory"); + addPrefixed("tooltip.battery.charge-help", "Sneak-right-click to toggle"); + // Storage addPrefixed("storage.crystal-flux", "%s/%s Crystal Flux");