Skip to content

Commit

Permalink
Make some of the creative hatches data stick copyable (#14)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Zorbatron authored Sep 9, 2024
1 parent 8afd1aa commit 77a3c5f
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ local.properties
run/
logs/
lib/
.run/
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.*;
Expand All @@ -46,7 +44,8 @@
import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockPart;

public class MetaTileEntityCreativeEnergyHatch extends MetaTileEntityMultiblockPart implements
IMultiblockAbilityPart<IEnergyContainer>, IControllable {
IMultiblockAbilityPart<IEnergyContainer>, IControllable,
IDataStickIntractable {

protected InfiniteEnergyContainer energyContainer;

Expand Down Expand Up @@ -89,8 +88,9 @@ public void addToMultiBlock(MultiblockControllerBase controllerBase) {
public void addInformation(ItemStack stack, @Nullable World world, List<String> 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
Expand All @@ -104,18 +104,26 @@ public long getVoltage() {
return this.voltage;
}

public void setVoltage(long voltage) {
protected void setVoltage(long voltage) {
this.voltage = voltage;
}

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;
Expand All @@ -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());

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -262,6 +270,7 @@ public <T> T getCapability(Capability<T> capability, EnumFacing side) {
if (capability == GregtechTileCapabilities.CAPABILITY_CONTROLLABLE) {
return GregtechTileCapabilities.CAPABILITY_CONTROLLABLE.cast(this);
}

return super.getCapability(capability, side);
}

Expand All @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -39,7 +42,7 @@
import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockNotifiablePart;

public class MetaTileEntityCreativeFluidHatch extends MetaTileEntityMultiblockNotifiablePart implements
IMultiblockAbilityPart<IFluidTank> {
IMultiblockAbilityPart<IFluidTank>, IDataStickIntractable {

private final InfiniteFluidTank fluidTank;

Expand Down Expand Up @@ -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"));
}

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -41,7 +43,8 @@
import gregtech.common.metatileentities.multi.multiblockpart.MetaTileEntityMultiblockNotifiablePart;

public class MetaTileEntityCreativeItemBus extends MetaTileEntityMultiblockNotifiablePart implements
IMultiblockAbilityPart<IItemHandlerModifiable>, IGhostSlotConfigurable {
IMultiblockAbilityPart<IItemHandlerModifiable>, IGhostSlotConfigurable,
IDataStickIntractable {

private InfiniteItemStackHandler infiniteItemStackHandler;
private GhostCircuitItemStackHandler circuitItemStackHandler;
Expand Down Expand Up @@ -173,8 +176,8 @@ public void readFromNBT(NBTTagCompound data) {
public void addInformation(ItemStack stack, @Nullable World world, List<String> 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
Expand All @@ -183,4 +186,35 @@ public void addToolUsages(ItemStack stack, @Nullable World world, List<String> 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);
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/zbgt/lang/en_us.lang
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 77a3c5f

Please sign in to comment.