From 77a3c5fed1e9c1c907cb2c9c457c6c82cc24e573 Mon Sep 17 00:00:00 2001 From: Zorbatron Date: Mon, 9 Sep 2024 16:34:39 -0400 Subject: [PATCH] Make some of the creative hatches data stick copyable (#14) * Data stick copying for the energy source/sink and fluid hatch * Data stick copying for the creative item bus * Mention in their tooltips that they're copyable --- .gitignore | 1 + .../MetaTileEntityCreativeEnergyHatch.java | 106 +++++++++++++----- .../MetaTileEntityCreativeFluidHatch.java | 37 +++++- .../MetaTileEntityCreativeItemBus.java | 38 ++++++- .../resources/assets/zbgt/lang/en_us.lang | 3 + 5 files changed, 154 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 85b1c007..d6a901b5 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,4 @@ local.properties run/ logs/ lib/ +.run/ \ No newline at end of file diff --git a/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeEnergyHatch.java b/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeEnergyHatch.java index c33cbc4b..7a37a9b4 100644 --- a/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeEnergyHatch.java +++ b/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeEnergyHatch.java @@ -12,6 +12,7 @@ import net.minecraft.network.PacketBuffer; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; @@ -24,10 +25,7 @@ import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; import gregtech.api.GTValues; -import gregtech.api.capability.GregtechDataCodes; -import gregtech.api.capability.GregtechTileCapabilities; -import gregtech.api.capability.IControllable; -import gregtech.api.capability.IEnergyContainer; +import gregtech.api.capability.*; import gregtech.api.gui.GuiTextures; import gregtech.api.gui.ModularUI; import gregtech.api.gui.widgets.*; @@ -46,7 +44,8 @@ import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockPart; public class MetaTileEntityCreativeEnergyHatch extends MetaTileEntityMultiblockPart implements - IMultiblockAbilityPart, IControllable { + IMultiblockAbilityPart, IControllable, + IDataStickIntractable { protected InfiniteEnergyContainer energyContainer; @@ -89,8 +88,9 @@ public void addToMultiBlock(MultiblockControllerBase controllerBase) { public void addInformation(ItemStack stack, @Nullable World world, List tooltip, boolean advanced) { tooltip.add(I18n.format("gregtech.creative_tooltip.1") + TooltipHelper.RAINBOW + I18n.format("gregtech.creative_tooltip.2") + I18n.format("gregtech.creative_tooltip.3")); - tooltip.add(I18n.format("gregtech.universal.enabled")); + tooltip.add(I18n.format("gregtech.machine.me.copy_paste.tooltip")); tooltip.add(I18n.format("zbgt.machine.creative_energy.warning.1")); + tooltip.add(I18n.format("gregtech.universal.enabled")); } @Override @@ -104,7 +104,7 @@ public long getVoltage() { return this.voltage; } - public void setVoltage(long voltage) { + protected void setVoltage(long voltage) { this.voltage = voltage; } @@ -112,10 +112,18 @@ public long getAmps() { return this.amps; } - public void setAmps(long amps) { + protected void setAmps(long amps) { this.amps = amps; } + public int getVoltageTier() { + return this.setTier; + } + + protected void setVoltageTier(int tier) { + this.setTier = tier; + } + @NotNull protected SimpleOverlayRenderer getOverlay() { return isExportHatch ? Textures.ENERGY_OUT_MULTI : Textures.ENERGY_IN_MULTI; @@ -137,8 +145,8 @@ protected ModularUI createUI(EntityPlayer entityPlayer) { // Voltage selector ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 138 + yOffset) .widget(new CycleButtonWidget(7, 7 + yOffset, 30, 20, GTValues.VNF, () -> setTier, tier -> { - setTier = tier; - voltage = GTValues.V[setTier]; + setVoltageTier(tier); + setVoltage(GTValues.V[getVoltageTier()]); })); builder.label(6, 6, getMetaFullName()); @@ -147,19 +155,19 @@ protected ModularUI createUI(EntityPlayer entityPlayer) { builder.widget(new TextFieldWidget2(9, 50 + yOffset, 152, 16, () -> String.valueOf(voltage), value -> { if (!value.isEmpty()) { setVoltage(Long.parseLong(value)); - setTier = GTUtility.getTierByVoltage(voltage); + setVoltageTier(GTUtility.getTierByVoltage(getVoltage())); } }).setAllowedChars(TextFieldWidget2.NATURAL_NUMS).setMaxLength(19).setValidator(getTextFieldValidator())); builder.label(7, 74 + yOffset, "gregtech.creative.energy.amperage"); builder.widget(new ClickButtonWidget(7, 87 + yOffset, 20, 20, "-", data -> { - if (amps > 0) { - setAmps(amps - 1); + if (getAmps() > 0) { + setAmps(getAmps() - 1); } })); builder.widget(new ClickButtonWidget(7, 111 + yOffset, 20, 20, "÷4", clickData -> { - if (amps / 4 > 0) { - setAmps(amps / 4); + if (getAmps() / 4 > 0) { + setAmps(getAmps() / 4); } else { setAmps(1); } @@ -171,19 +179,19 @@ protected ModularUI createUI(EntityPlayer entityPlayer) { } }).setMaxLength(10).setNumbersOnly(0, Integer.MAX_VALUE)); builder.widget(new ClickButtonWidget(149, 87 + yOffset, 20, 20, "+", data -> { - if (amps < Integer.MAX_VALUE) { - setAmps(amps + 1); + if (getAmps() < Integer.MAX_VALUE) { + setAmps(getAmps() + 1); } })); builder.widget(new ClickButtonWidget(149, 111 + yOffset, 20, 20, "x4", data -> { - if (amps * 4 <= Integer.MAX_VALUE) { - setAmps(amps * 4); + if (getAmps() * 4 <= Integer.MAX_VALUE) { + setAmps(getAmps() * 4); } })); - builder.widget( - new ImageCycleButtonWidget(149, 8 + yOffset, 18, 18, GuiTextures.BUTTON_POWER, this::isWorkingEnabled, - this::setWorkingEnabled)); + builder.widget(new ImageCycleButtonWidget(149, 8 + yOffset, 18, 18, GuiTextures.BUTTON_POWER, + this::isWorkingEnabled, + this::setWorkingEnabled)); return builder.build(getHolder(), entityPlayer); } @@ -242,17 +250,17 @@ public void receiveCustomData(int dataId, @NotNull PacketBuffer buf) { @Override public NBTTagCompound writeToNBT(NBTTagCompound data) { - data.setLong("Voltage", this.voltage); - data.setLong("Amps", this.amps); - data.setByte("Tier", (byte) this.setTier); + data.setLong("Voltage", getVoltage()); + data.setLong("Amps", getAmps()); + data.setByte("Tier", (byte) getVoltageTier()); return super.writeToNBT(data); } @Override public void readFromNBT(NBTTagCompound data) { - this.voltage = data.getLong("Voltage"); - this.amps = data.getLong("Amps"); - this.setTier = data.getByte("Tier"); + setVoltage(data.getLong("Voltage")); + setAmps(data.getLong("Amps")); + setVoltageTier(data.getByte("Tier")); super.readFromNBT(data); setInitialEnergyConfiguration(); } @@ -262,6 +270,7 @@ public T getCapability(Capability capability, EnumFacing side) { if (capability == GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) { return GregtechTileCapabilities.CAPABILITY_CONTROLLABLE.cast(this); } + return super.getCapability(capability, side); } @@ -276,4 +285,45 @@ public void receiveInitialSyncData(@NotNull PacketBuffer buf) { super.receiveInitialSyncData(buf); this.isWorkingEnabled = buf.readBoolean(); } + + @Override + public void onDataStickLeftClick(EntityPlayer player, ItemStack dataStick) { + NBTTagCompound tag = new NBTTagCompound(); + tag.setTag(isExportHatch ? "CreativeEnergySink" : "CreativeEnergySource", writeConfigToTag()); + dataStick.setTagCompound(tag); + dataStick.setTranslatableName("zbgt.machine.creative_energy_source.data_stick.name"); + player.sendStatusMessage(new TextComponentTranslation("gregtech.machine.me.import_copy_settings"), true); + } + + private NBTTagCompound writeConfigToTag() { + NBTTagCompound tag = new NBTTagCompound(); + + tag.setLong("Voltage", getVoltage()); + tag.setLong("Amperage", getAmps()); + tag.setInteger("Tier", getVoltageTier()); + tag.setBoolean("IsWorkingEnabled", isWorkingEnabled()); + + return tag; + } + + @Override + public boolean onDataStickRightClick(EntityPlayer player, ItemStack dataStick) { + NBTTagCompound tag = dataStick.getTagCompound(); + + if (tag == null) return false; + if (!(tag.hasKey("CreativeEnergySink") || tag.hasKey("CreativeEnergySource"))) return false; + + readConfigFromTag( + isExportHatch ? tag.getCompoundTag("CreativeEnergySink") : tag.getCompoundTag("CreativeEnergySource")); + player.sendStatusMessage(new TextComponentTranslation("gregtech.machine.me.import_paste_settings"), true); + + return true; + } + + private void readConfigFromTag(NBTTagCompound tag) { + setVoltage(tag.getLong("Voltage")); + setAmps(tag.getLong("Amperage")); + setVoltageTier(tag.getInteger("Tier")); + setWorkingEnabled(tag.getBoolean("IsWorkingEnabled")); + } } diff --git a/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeFluidHatch.java b/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeFluidHatch.java index ef073fd4..082b7c85 100644 --- a/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeFluidHatch.java +++ b/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeFluidHatch.java @@ -9,8 +9,10 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidTank; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import net.minecraftforge.items.IItemHandlerModifiable; @@ -26,6 +28,7 @@ import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; import gregtech.api.GTValues; +import gregtech.api.capability.IDataStickIntractable; import gregtech.api.capability.impl.FilteredItemHandler; import gregtech.api.capability.impl.FluidTankList; import gregtech.api.gui.GuiTextures; @@ -39,7 +42,7 @@ import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockNotifiablePart; public class MetaTileEntityCreativeFluidHatch extends MetaTileEntityMultiblockNotifiablePart implements - IMultiblockAbilityPart { + IMultiblockAbilityPart, IDataStickIntractable { private final InfiniteFluidTank fluidTank; @@ -144,6 +147,7 @@ public void addInformation(ItemStack stack, @Nullable World player, @NotNull Lis boolean advanced) { tooltip.add(I18n.format("gregtech.creative_tooltip.1") + TooltipHelper.RAINBOW + I18n.format("gregtech.creative_tooltip.2") + I18n.format("gregtech.creative_tooltip.3")); + tooltip.add(I18n.format("gregtech.machine.me.copy_paste.tooltip")); tooltip.add(I18n.format("gregtech.universal.enabled")); } @@ -166,4 +170,35 @@ public void readFromNBT(NBTTagCompound data) { super.readFromNBT(data); } + + @Override + public void onDataStickLeftClick(EntityPlayer player, ItemStack dataStick) { + NBTTagCompound tag = new NBTTagCompound(); + tag.setTag("CreativeFluidHatch", writeConfigToTag()); + dataStick.setTagCompound(tag); + dataStick.setTranslatableName("zbgt.machine.creative_reservoir_hatch.data_stick.name"); + player.sendStatusMessage(new TextComponentTranslation("gregtech.machine.me.import_copy_settings"), true); + } + + private NBTTagCompound writeConfigToTag() { + NBTTagCompound tag = new NBTTagCompound(); + + return fluidTank.writeToNBT(tag); + } + + @Override + public boolean onDataStickRightClick(EntityPlayer player, ItemStack dataStick) { + NBTTagCompound tag = dataStick.getTagCompound(); + + if (tag == null || !tag.hasKey("CreativeFluidHatch")) return false; + + readConfigFromTag(tag.getCompoundTag("CreativeFluidHatch")); + player.sendStatusMessage(new TextComponentTranslation("gregtech.machine.me.import_paste_settings"), true); + + return true; + } + + private void readConfigFromTag(NBTTagCompound tag) { + fluidTank.setFluid(FluidStack.loadFluidStackFromNBT(tag)); + } } diff --git a/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeItemBus.java b/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeItemBus.java index 0ae57aa2..c2fd5f75 100644 --- a/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeItemBus.java +++ b/src/main/java/com/zorbatron/zbgt/common/metatileentities/multi/multiblockpart/MetaTileEntityCreativeItemBus.java @@ -8,6 +8,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraftforge.items.IItemHandlerModifiable; @@ -22,6 +23,7 @@ import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Matrix4; import gregtech.api.GTValues; +import gregtech.api.capability.IDataStickIntractable; import gregtech.api.capability.IGhostSlotConfigurable; import gregtech.api.capability.impl.GhostCircuitItemStackHandler; import gregtech.api.capability.impl.ItemHandlerList; @@ -41,7 +43,8 @@ import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockNotifiablePart; public class MetaTileEntityCreativeItemBus extends MetaTileEntityMultiblockNotifiablePart implements - IMultiblockAbilityPart, IGhostSlotConfigurable { + IMultiblockAbilityPart, IGhostSlotConfigurable, + IDataStickIntractable { private InfiniteItemStackHandler infiniteItemStackHandler; private GhostCircuitItemStackHandler circuitItemStackHandler; @@ -173,8 +176,8 @@ public void readFromNBT(NBTTagCompound data) { public void addInformation(ItemStack stack, @Nullable World world, List tooltip, boolean advanced) { tooltip.add(I18n.format("gregtech.creative_tooltip.1") + TooltipHelper.RAINBOW + I18n.format("gregtech.creative_tooltip.2") + I18n.format("gregtech.creative_tooltip.3")); + tooltip.add(I18n.format("gregtech.machine.me.copy_paste.tooltip")); tooltip.add(I18n.format("gregtech.universal.enabled")); - tooltip.add(I18n.format("zbgt.machine.creative_energy.warning.1")); } @Override @@ -183,4 +186,35 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List t tooltip.add(I18n.format("gregtech.tool_action.wrench.set_facing")); super.addToolUsages(stack, world, tooltip, advanced); } + + @Override + public void onDataStickLeftClick(EntityPlayer player, ItemStack dataStick) { + NBTTagCompound tag = new NBTTagCompound(); + tag.setTag("CreativeItemBus", writeConfigToTag()); + dataStick.setTagCompound(tag); + dataStick.setTranslatableName("zbgt.machine.creative_item_bus.data_stick.name"); + player.sendStatusMessage(new TextComponentTranslation("gregtech.machine.me.import_copy_settings"), true); + } + + private NBTTagCompound writeConfigToTag() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setTag("Inventory", infiniteItemStackHandler.serializeNBT()); + this.circuitItemStackHandler.write(tag); + return tag; + } + + @Override + public boolean onDataStickRightClick(EntityPlayer player, ItemStack dataStick) { + NBTTagCompound tag = dataStick.getTagCompound(); + if (tag == null || !tag.hasKey("CreativeItemBus")) return false; + + readConfigFromTag(tag.getCompoundTag("CreativeItemBus")); + + return true; + } + + private void readConfigFromTag(NBTTagCompound tag) { + this.infiniteItemStackHandler.deserializeNBT(tag.getCompoundTag("Inventory")); + this.circuitItemStackHandler.read(tag); + } } diff --git a/src/main/resources/assets/zbgt/lang/en_us.lang b/src/main/resources/assets/zbgt/lang/en_us.lang index b16d58f5..5073c00e 100644 --- a/src/main/resources/assets/zbgt/lang/en_us.lang +++ b/src/main/resources/assets/zbgt/lang/en_us.lang @@ -1,6 +1,7 @@ # Multiblock parts zbgt.machine.creative_energy_source.name=Creative Energy Source zbgt.machine.creative_energy_source.tooltip=Infinite Energy Source for Multiblocks +zbgt.machine.creative_energy_source.data_stick.name=§oCreative Energy Source Configuration Data zbgt.machine.creative_energy_sink.name=Creative Energy Sink zbgt.machine.creative_energy_sink.tooltip=Infinite Energy Sink for Multiblocks @@ -10,6 +11,7 @@ zbgt.machine.creative_energy.warning.1=Changing settings requires the multiblock zbgt.machine.creative_reservoir_hatch.name=Creative Fluid Hatch zbgt.machine.creative_reservoir_hatch.tooltip=Infinite fluid source for multiblocks +zbgt.machine.creative_reservoir_hatch.data_stick.name=§oCreative Fluid Hatch Configuration Data zbgt.machine.creative_computation_provider.name=Creative Computation Provider zbgt.machine.creative_computation_provider.tooltip=Infinite source of computation for CWU consumers @@ -18,6 +20,7 @@ zbgt.machine.creative_computation_provider.cwut=Maximum Requestable CWU/t zbgt.machine.creative_item_bus.name=Creative Item Bus zbgt.machine.creative_item_bus.tooltip=Infinite item source for multiblocks +zbgt.machine.creative_item_bus.data_stick.name=§oCreative Item Bus Configuration Data zbgt.machine.air_intake_universal.rate=Collects %,d mB of air every %,d ticks