diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/gregtech/api/util/GTUtil.java | 73 | ||||
-rw-r--r-- | src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java | 36 |
2 files changed, 88 insertions, 21 deletions
diff --git a/src/main/java/gregtech/api/util/GTUtil.java b/src/main/java/gregtech/api/util/GTUtil.java index db2a628bbe..d1dd308449 100644 --- a/src/main/java/gregtech/api/util/GTUtil.java +++ b/src/main/java/gregtech/api/util/GTUtil.java @@ -2,6 +2,7 @@ package gregtech.api.util; import static gregtech.api.util.GTUtility.filterValidMTEs; +import java.util.ArrayList; import java.util.List; import net.minecraft.block.Block; @@ -24,6 +25,7 @@ import gregtech.api.metatileentity.implementations.MTEHatch; import gregtech.api.metatileentity.implementations.MTEMultiBlockBase; import gregtech.api.multitileentity.interfaces.IMultiTileEntity; import gregtech.common.items.behaviors.BehaviourDataOrb; +import gregtech.common.tileentities.machines.IDualInputHatch; public class GTUtil { @@ -240,9 +242,21 @@ public class GTUtil { if (list == null) return false; newTag.setTag("mOutputBusses", list); count += list.tagCount(); + + // For Crafting Input Proxy + ArrayList<MTEHatch> dualInputHatches = new ArrayList<>(); + for (IDualInputHatch dualInputHatch : controller.mDualInputHatches) { + if (dualInputHatch instanceof MTEHatch hatch) { + dualInputHatches.add(hatch); + } + } + list = saveConfigurationToDataStick(player, dualInputHatches); + if (list == null) return false; + newTag.setTag("mDualInputHatches", list); + count += list.tagCount(); + // Output hatch config currently cannot be copied, so we omit this part for now - // TODO this doesn't work for now - // newTag.setTag("mDualInputHatches", saveToDataStick(player, controller.mDualInputHatches)); + dataOrb.setTagCompound(newTag); BehaviourDataOrb.setDataTitle(dataOrb, "Multiblock Hatch Configuration"); BehaviourDataOrb.setDataName(dataOrb, String.format("%s configuration saved", count)); @@ -266,32 +280,51 @@ public class GTUtil { return false; } NBTTagCompound tag = dataOrb.getTagCompound(); - if (!checkCanLoadConfigurationFromDataStick( + if (checkCanLoadConfigurationFromDataStick( tag.getTagList("mInputBusses", Constants.NBT.TAG_COMPOUND), player, - controller.mInputBusses) - || !checkCanLoadConfigurationFromDataStick( + controller.mInputBusses)) { + if (!loadConfigurationFromDataStick( + tag.getTagList("mInputBusses", Constants.NBT.TAG_COMPOUND), + player, + controller.mInputBusses)) return false; + } + if (checkCanLoadConfigurationFromDataStick( + tag.getTagList("mInputHatches", Constants.NBT.TAG_COMPOUND), + player, + controller.mInputHatches)) { + if (!loadConfigurationFromDataStick( tag.getTagList("mInputHatches", Constants.NBT.TAG_COMPOUND), player, - controller.mInputHatches) - || !checkCanLoadConfigurationFromDataStick( + controller.mInputHatches)) return false; + } + if (checkCanLoadConfigurationFromDataStick( + tag.getTagList("mOutputBusses", Constants.NBT.TAG_COMPOUND), + player, + controller.mOutputBusses)) { + if (!loadConfigurationFromDataStick( tag.getTagList("mOutputBusses", Constants.NBT.TAG_COMPOUND), player, - controller.mOutputBusses)) - return false; + controller.mOutputBusses)) return false; + } - if (!loadConfigurationFromDataStick( - tag.getTagList("mInputBusses", Constants.NBT.TAG_COMPOUND), - player, - controller.mInputBusses)) return false; - if (!loadConfigurationFromDataStick( - tag.getTagList("mInputHatches", Constants.NBT.TAG_COMPOUND), - player, - controller.mInputHatches)) return false; - if (!loadConfigurationFromDataStick( - tag.getTagList("mOutputBusses", Constants.NBT.TAG_COMPOUND), + // For Crafting Input Proxy + ArrayList<MTEHatch> dualInputHatches = new ArrayList<>(); + for (IDualInputHatch dualInputHatch : controller.mDualInputHatches) { + if (dualInputHatch instanceof MTEHatch hatch) { + dualInputHatches.add(hatch); + } + } + if (checkCanLoadConfigurationFromDataStick( + tag.getTagList("mDualInputHatches", Constants.NBT.TAG_COMPOUND), player, - controller.mOutputBusses)) return false; + dualInputHatches)) { + if (!loadConfigurationFromDataStick( + tag.getTagList("mDualInputHatches", Constants.NBT.TAG_COMPOUND), + player, + dualInputHatches)) return false; + } + return true; } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java index 92cbb0d6e8..35db434a32 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java @@ -20,6 +20,7 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import gregtech.api.enums.ItemList; +import gregtech.api.interfaces.IDataCopyable; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; @@ -28,8 +29,9 @@ import gregtech.api.render.TextureFactory; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; -public class MTEHatchCraftingInputSlave extends MTEHatchInputBus implements IDualInputHatch { +public class MTEHatchCraftingInputSlave extends MTEHatchInputBus implements IDualInputHatch, IDataCopyable { + public static final String COPIED_DATA_IDENTIFIER = "craftingInputProxy"; private MTEHatchCraftingInputME master; // use getMaster() to access private int masterX, masterY, masterZ; private boolean masterSet = false; // indicate if values of masterX, masterY, masterZ are valid @@ -220,6 +222,38 @@ public class MTEHatchCraftingInputSlave extends MTEHatchInputBus implements IDua } @Override + public String getCopiedDataIdentifier(EntityPlayer player) { + return COPIED_DATA_IDENTIFIER; + } + + @Override + public boolean pasteCopiedData(EntityPlayer player, NBTTagCompound nbt) { + if (nbt == null || !COPIED_DATA_IDENTIFIER.equals(nbt.getString("type"))) return false; + if (nbt.hasKey("master")) { + NBTTagCompound masterNBT = nbt.getCompoundTag("master"); + masterX = masterNBT.getInteger("x"); + masterY = masterNBT.getInteger("y"); + masterZ = masterNBT.getInteger("z"); + masterSet = true; + } + return true; + } + + @Override + public NBTTagCompound getCopiedData(EntityPlayer player) { + NBTTagCompound tag = new NBTTagCompound(); + tag.setString("type", COPIED_DATA_IDENTIFIER); + if (masterSet) { + NBTTagCompound masterNBT = new NBTTagCompound(); + masterNBT.setInteger("x", masterX); + masterNBT.setInteger("y", masterY); + masterNBT.setInteger("z", masterZ); + tag.setTag("master", masterNBT); + } + return tag; + } + + @Override public void getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { NBTTagCompound tag = accessor.getNBTData(); |