aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorGlease <4586901+Glease@users.noreply.github.com>2024-08-28 06:55:12 +0800
committerGitHub <noreply@github.com>2024-08-27 22:55:12 +0000
commit432bb57cab4e575f63203536e105af81e28e41bf (patch)
treeb44b53b7c6a8d30ffd5c23c004ac8ca6c5c3c501 /src/main/java
parentefef6ba7b449de1af1e14f6cec141a101d7b1e8d (diff)
downloadGT5-Unofficial-432bb57cab4e575f63203536e105af81e28e41bf.tar.gz
GT5-Unofficial-432bb57cab4e575f63203536e105af81e28e41bf.tar.bz2
GT5-Unofficial-432bb57cab4e575f63203536e105af81e28e41bf.zip
implement whole multiblock hatch configuration copying (#2965)
enable whole multiblock hatch configuration copying does not include crafting bus for now Co-authored-by: Martin Robertz <dream-master@gmx.net> Co-authored-by: boubou19 <miisterunknown@gmail.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_CircuitAssemblyLine.java37
-rw-r--r--src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java3
-rw-r--r--src/main/java/gregtech/api/interfaces/IDataCopyable.java30
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java38
-rw-r--r--src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java30
-rw-r--r--src/main/java/gregtech/api/util/GT_Util.java153
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java50
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Input_ME.java62
-rw-r--r--src/main/java/gregtech/common/tools/GT_Tool_Wrench.java1
-rw-r--r--src/main/java/net/glease/ggfab/mte/MTE_LinkedInputBus.java76
10 files changed, 398 insertions, 82 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_CircuitAssemblyLine.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_CircuitAssemblyLine.java
index 5a8c1e054c..3a81a89386 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_CircuitAssemblyLine.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/tileentities/multis/GT_TileEntity_CircuitAssemblyLine.java
@@ -211,7 +211,7 @@ public class GT_TileEntity_CircuitAssemblyLine extends
public String getTypeForDisplay() {
- if (this.type.equals(new NBTTagCompound())) return "";
+ if (!isImprinted()) return "";
return GT_LanguageManager.getTranslation(
GT_LanguageManager.getTranslateableItemStackName(CircuitImprintLoader.getStackFromTag(this.type)));
}
@@ -226,15 +226,20 @@ public class GT_TileEntity_CircuitAssemblyLine extends
super(aName);
}
+ public boolean isImprinted() {
+ return !this.type.hasNoTags();
+ }
+
private boolean imprintMachine(ItemStack itemStack) {
- if (!this.type.equals(new NBTTagCompound())) return true;
+ if (isImprinted()) return true;
if (!GT_Utility.isStackValid(itemStack)) return false;
if (itemStack.getItem() instanceof BW_Meta_Items.BW_GT_MetaGenCircuits && itemStack.getItemDamage() == 0
- && itemStack.getTagCompound() != null
- && this.type.equals(new NBTTagCompound())) {
+ && itemStack.getTagCompound() != null) {
this.type = itemStack.getTagCompound();
- this.mInventory[1].stackSize -= 1;
- if (this.mInventory[1].stackSize <= 0) this.mInventory[1] = null;
+ itemStack.stackSize -= 1;
+ if (itemStack == getControllerSlot() && itemStack.stackSize <= 0) {
+ mInventory[getControllerSlotIndex()] = null;
+ }
this.getBaseMetaTileEntity()
.issueBlockUpdate();
return true;
@@ -269,20 +274,34 @@ public class GT_TileEntity_CircuitAssemblyLine extends
@Override
public void setItemNBT(NBTTagCompound aNBT) {
- if (!this.type.equals(new NBTTagCompound())) aNBT.setTag(IMPRINT_KEY, this.type);
+ if (isImprinted()) aNBT.setTag(IMPRINT_KEY, this.type);
aNBT.setInteger(RUNNING_MODE_KEY, mode);
super.saveNBTData(aNBT);
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
- if (!this.type.equals(new NBTTagCompound())) aNBT.setTag(IMPRINT_KEY, this.type);
+ if (isImprinted()) aNBT.setTag(IMPRINT_KEY, this.type);
aNBT.setInteger(RUNNING_MODE_KEY, mode);
aNBT.setInteger(LENGTH_KEY, length);
super.saveNBTData(aNBT);
}
@Override
+ public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
+ if (mode == 0 && !isImprinted() && getBaseMetaTileEntity().isServerSide()) {
+ ItemStack heldItem = aPlayer.getHeldItem();
+ if (imprintMachine(heldItem)) {
+ if (heldItem.stackSize <= 0) {
+ aPlayer.inventory.setInventorySlotContents(aPlayer.inventory.currentItem, null);
+ }
+ return;
+ }
+ }
+ super.onLeftclick(aBaseMetaTileEntity, aPlayer);
+ }
+
+ @Override
public final void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) {
if (getBaseMetaTileEntity().isServerSide()) {
this.mode = (this.mode + 1) % 2;
@@ -324,7 +343,7 @@ public class GT_TileEntity_CircuitAssemblyLine extends
@Override
public CheckRecipeResult checkProcessing() {
if (mode == 0) {
- if (this.type.equals(new NBTTagCompound()) && !this.imprintMachine(this.getControllerSlot()))
+ if (!isImprinted() && !this.imprintMachine(this.getControllerSlot()))
return SimpleCheckRecipeResult.ofFailure("no_imprint");
if (this.imprintedItemName == null || this.imprintedStack == null) {
this.imprintedStack = new ItemStack(BW_Meta_Items.getCircuitParts(), 1, 0);
diff --git a/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java b/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java
index 89a0835f13..ea9a39bdf8 100644
--- a/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java
+++ b/src/main/java/gregtech/api/gui/modularui/GT_UIInfos.java
@@ -7,6 +7,7 @@ import java.util.function.Function;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
+import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.ForgeDirection;
import com.gtnewhorizons.modularui.api.UIInfos;
@@ -98,7 +99,7 @@ public class GT_UIInfos {
* Opens TileEntity UI, created by {@link ITileWithModularUI#createWindow}.
*/
public static void openGTTileEntityUI(IHasWorldObjectAndCoords aTileEntity, EntityPlayer aPlayer) {
- if (aTileEntity.isClientSide()) return;
+ if (aTileEntity.isClientSide() || aPlayer instanceof FakePlayer) return;
GTTileEntityDefaultUI.open(
aPlayer,
aTileEntity.getWorld(),
diff --git a/src/main/java/gregtech/api/interfaces/IDataCopyable.java b/src/main/java/gregtech/api/interfaces/IDataCopyable.java
new file mode 100644
index 0000000000..9994354fa7
--- /dev/null
+++ b/src/main/java/gregtech/api/interfaces/IDataCopyable.java
@@ -0,0 +1,30 @@
+package gregtech.api.interfaces;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.nbt.NBTTagCompound;
+
+public interface IDataCopyable {
+
+ /**
+ * Implementation will set the type field. caller can assume the returned tag (if not null) always contains a "type"
+ * field
+ * with a value of {@link #getCopiedDataIdentifier(EntityPlayer)}
+ * Implementation should not try to alert player of situations that copy has failed.
+ *
+ * @return null if cannot copy (e.g. not properly configured yet) or the data to copy.
+ */
+ NBTTagCompound getCopiedData(EntityPlayer player);
+
+ /**
+ * Callee should check if the given tag is valid.
+ * Implementation should not try to alert player of situations that paste has failed.
+ *
+ * @return true if pasted. false otherwise.
+ */
+ boolean pasteCopiedData(EntityPlayer player, NBTTagCompound nbt);
+
+ /**
+ * @return the type identifier. this should be a constant for the given set of arguments.
+ */
+ String getCopiedDataIdentifier(EntityPlayer player);
+}
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java
index 5fdfa7899b..0bfe55cac1 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_OutputBus.java
@@ -22,6 +22,7 @@ import gregtech.GT_Mod;
import gregtech.api.enums.ItemList;
import gregtech.api.gui.modularui.GT_UIInfos;
import gregtech.api.gui.widgets.GT_PhantomItemButton;
+import gregtech.api.interfaces.IDataCopyable;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IItemLockable;
import gregtech.api.interfaces.modularui.IAddUIWidgets;
@@ -31,7 +32,8 @@ import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.extensions.ArrayExt;
-public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch implements IAddUIWidgets, IItemLockable {
+public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch
+ implements IAddUIWidgets, IItemLockable, IDataCopyable {
private static final String DATA_STICK_DATA_TYPE = "outputBusFilter";
private static final String LOCKED_ITEM_NBT_KEY = "lockedItem";
@@ -127,17 +129,11 @@ public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch i
return super.onRightclick(aBaseMetaTileEntity, aPlayer);
}
- if (!dataStick.hasTagCompound() || !DATA_STICK_DATA_TYPE.equals(dataStick.stackTagCompound.getString("type"))) {
+ if (!pasteCopiedData(aPlayer, dataStick.stackTagCompound)) {
aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.output_bus.invalid"));
return false;
}
- final NBTTagCompound nbt = dataStick.stackTagCompound;
- if (nbt.hasKey(LOCKED_ITEM_NBT_KEY)) {
- lockedItem = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag(LOCKED_ITEM_NBT_KEY));
- } else {
- lockedItem = null;
- }
aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.output_bus.loaded"));
return true;
@@ -153,15 +149,35 @@ public class GT_MetaTileEntity_Hatch_OutputBus extends GT_MetaTileEntity_Hatch i
return;
}
+ dataStick.stackTagCompound = getCopiedData(aPlayer);
+ dataStick.setStackDisplayName("Output Bus Configuration");
+ aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.output_bus.saved"));
+ }
+
+ @Override
+ public NBTTagCompound getCopiedData(EntityPlayer player) {
final NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("type", DATA_STICK_DATA_TYPE);
if (lockedItem != null) {
nbt.setTag(LOCKED_ITEM_NBT_KEY, lockedItem.writeToNBT(new NBTTagCompound()));
}
+ return nbt;
+ }
- dataStick.stackTagCompound = nbt;
- dataStick.setStackDisplayName("Output Bus Configuration");
- aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.output_bus.saved"));
+ @Override
+ public boolean pasteCopiedData(EntityPlayer player, NBTTagCompound nbt) {
+ if (nbt == null || !DATA_STICK_DATA_TYPE.equals(nbt.getString("type"))) return false;
+ if (nbt.hasKey(LOCKED_ITEM_NBT_KEY)) {
+ lockedItem = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag(LOCKED_ITEM_NBT_KEY));
+ } else {
+ lockedItem = null;
+ }
+ return true;
+ }
+
+ @Override
+ public String getCopiedDataIdentifier(EntityPlayer player) {
+ return DATA_STICK_DATA_TYPE;
}
/**
diff --git a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
index fb77abd8b2..709191f10c 100644
--- a/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
+++ b/src/main/java/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_MultiBlockBase.java
@@ -28,6 +28,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
@@ -84,6 +85,7 @@ import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_OverclockCalculator;
import gregtech.api.util.GT_ParallelHelper;
import gregtech.api.util.GT_Recipe;
+import gregtech.api.util.GT_Util;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.GT_Waila;
import gregtech.api.util.OutputHatchWrapper;
@@ -344,8 +346,36 @@ public abstract class GT_MetaTileEntity_MultiBlockBase extends MetaTileEntity
return SingleRecipeCheck.tryLoad(getRecipeMap(), aNBT);
}
+ public boolean saveOtherHatchConfiguration(EntityPlayer player) {
+ return true;
+ }
+
+ public boolean loadOtherHatchConfiguration(EntityPlayer player) {
+ return true;
+ }
+
+ @Override
+ public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
+ if (aBaseMetaTileEntity.isServerSide() && GT_Util.saveMultiblockInputConfiguration(this, aPlayer)) {
+ aPlayer.addChatComponentMessage(new ChatComponentTranslation("GT5U.MULTI_MACHINE_CONFIG.SAVE"));
+ return;
+ }
+ super.onLeftclick(aBaseMetaTileEntity, aPlayer);
+ }
+
@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
+ if (GT_Util.hasMultiblockInputConfiguration(aPlayer.getHeldItem())) {
+ if (aBaseMetaTileEntity.isServerSide()) {
+ if (GT_Util.loadMultiblockInputConfiguration(this, aPlayer)) {
+ aPlayer.addChatComponentMessage(new ChatComponentTranslation("GT5U.MULTI_MACHINE_CONFIG.LOAD"));
+ } else {
+ aPlayer
+ .addChatComponentMessage(new ChatComponentTranslation("GT5U.MULTI_MACHINE_CONFIG.LOAD.FAIL"));
+ }
+ }
+ return true;
+ }
GT_UIInfos.openGTTileEntityUI(aBaseMetaTileEntity, aPlayer);
return true;
}
diff --git a/src/main/java/gregtech/api/util/GT_Util.java b/src/main/java/gregtech/api/util/GT_Util.java
index 62ebcecd79..cdca6a1b9e 100644
--- a/src/main/java/gregtech/api/util/GT_Util.java
+++ b/src/main/java/gregtech/api/util/GT_Util.java
@@ -1,16 +1,29 @@
package gregtech.api.util;
+import static gregtech.api.util.GT_Utility.filterValidMTEs;
+
+import java.util.List;
+
import net.minecraft.block.Block;
+import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
+import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.Tuple;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
+import net.minecraftforge.common.util.Constants;
+import gregtech.api.enums.ItemList;
+import gregtech.api.interfaces.IDataCopyable;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
import gregtech.api.multitileentity.interfaces.IMultiTileEntity;
+import gregtech.common.items.behaviors.Behaviour_DataOrb;
public class GT_Util {
@@ -99,7 +112,9 @@ public class GT_Util {
return null;
}
- /** Sets the TileEntity at the passed position, with the option of turning adjacent TileEntity updates off. */
+ /**
+ * Sets the TileEntity at the passed position, with the option of turning adjacent TileEntity updates off.
+ */
public static TileEntity setTileEntity(World world, int x, int y, int z, TileEntity aTileEntity,
boolean aCauseTileEntityUpdates) {
if (aCauseTileEntityUpdates) world.setTileEntity(x, y, z, aTileEntity);
@@ -128,7 +143,9 @@ public class GT_Util {
return getTileEntity(world, coords.posX, coords.posY, coords.posZ, loadUnloadedChunks);
}
- /** Marks a Chunk dirty so it is saved */
+ /**
+ * Marks a Chunk dirty so it is saved
+ */
public static boolean markChunkDirty(World world, int x, int z) {
if (world == null || world.isRemote) return false;
Chunk aChunk = world.getChunkFromBlockCoords(x, z);
@@ -145,7 +162,9 @@ public class GT_Util {
return true;
}
- /** Marks a Chunk dirty so it is saved */
+ /**
+ * Marks a Chunk dirty so it is saved
+ */
public static boolean markChunkDirty(Object maybeTile) {
return maybeTile instanceof TileEntity tileEntity
&& markChunkDirty(tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.zCoord);
@@ -197,4 +216,132 @@ public class GT_Util {
public static short getA(int aColors) {
return (short) ((aColors >>> 24) & 255);
}
+
+ public static boolean saveMultiblockInputConfiguration(GT_MetaTileEntity_MultiBlockBase controller,
+ EntityPlayer player) {
+ NBTTagCompound newTag = new NBTTagCompound();
+ ItemStack dataOrb = player.getHeldItem();
+ if (GT_Utility.isStackInvalid(dataOrb) || !ItemList.Tool_DataOrb.isStackEqual(dataOrb, false, true)) {
+ return false;
+ }
+ if (!controller.saveOtherHatchConfiguration(player)) {
+ return false;
+ }
+ newTag.setString("type", "MultiblockConfiguration");
+ int count = 0;
+ NBTTagList list = saveConfigurationToDataStick(player, controller.mInputBusses);
+ if (list == null) return false;
+ newTag.setTag("mInputBusses", list);
+ count += list.tagCount();
+ list = saveConfigurationToDataStick(player, controller.mInputHatches);
+ if (list == null) return false;
+ newTag.setTag("mInputHatches", list);
+ count += list.tagCount();
+ list = saveConfigurationToDataStick(player, controller.mOutputBusses);
+ if (list == null) return false;
+ newTag.setTag("mOutputBusses", 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);
+ Behaviour_DataOrb.setDataTitle(dataOrb, "Multiblock Hatch Configuration");
+ Behaviour_DataOrb.setDataName(dataOrb, String.format("%s configuration saved", count));
+ return true;
+ }
+
+ public static boolean hasMultiblockInputConfiguration(ItemStack dataOrb) {
+ return !GT_Utility.isStackInvalid(dataOrb) && ItemList.Tool_DataOrb.isStackEqual(dataOrb, false, true)
+ && dataOrb.getTagCompound() != null
+ && "MultiblockConfiguration".equals(
+ dataOrb.getTagCompound()
+ .getString("type"));
+ }
+
+ public static boolean loadMultiblockInputConfiguration(GT_MetaTileEntity_MultiBlockBase controller,
+ EntityPlayer player) {
+ ItemStack dataOrb = player.getHeldItem();
+ if (!hasMultiblockInputConfiguration(dataOrb)) {
+ return false;
+ }
+ if (!controller.loadOtherHatchConfiguration(player)) {
+ return false;
+ }
+ NBTTagCompound tag = dataOrb.getTagCompound();
+ if (!checkCanLoadConfigurationFromDataStick(
+ tag.getTagList("mInputBusses", Constants.NBT.TAG_COMPOUND),
+ player,
+ controller.mInputBusses)
+ || !checkCanLoadConfigurationFromDataStick(
+ tag.getTagList("mInputHatches", Constants.NBT.TAG_COMPOUND),
+ player,
+ controller.mInputHatches)
+ || !checkCanLoadConfigurationFromDataStick(
+ tag.getTagList("mOutputBusses", Constants.NBT.TAG_COMPOUND),
+ player,
+ 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),
+ player,
+ controller.mOutputBusses)) return false;
+ return true;
+ }
+
+ private static NBTTagList saveConfigurationToDataStick(EntityPlayer player,
+ List<? extends GT_MetaTileEntity_Hatch> hatches) {
+ NBTTagList list = new NBTTagList();
+ for (GT_MetaTileEntity_Hatch tHatch : filterValidMTEs(hatches)) {
+ if (!(tHatch instanceof IDataCopyable copyable)) {
+ list.appendTag(new NBTTagCompound());
+ continue;
+ }
+ NBTTagCompound tag = copyable.getCopiedData(player);
+ if (tag == null) return null;
+ list.appendTag(tag);
+ }
+ return list;
+ }
+
+ private static boolean loadConfigurationFromDataStick(NBTTagList list, EntityPlayer player,
+ List<? extends GT_MetaTileEntity_Hatch> hatches) {
+ if (list == null || list.tagList.isEmpty()) return false;
+ List<? extends GT_MetaTileEntity_Hatch> validMTEs = filterValidMTEs(hatches);
+ int end = Math.min(validMTEs.size(), list.tagCount());
+ for (int i = 0; i < end; i++) {
+ GT_MetaTileEntity_Hatch tHatch = validMTEs.get(i);
+ NBTTagCompound tag = list.getCompoundTagAt(i);
+ if (!(tHatch instanceof IDataCopyable copyable)) {
+ if (tag.hasNoTags()) continue;
+ return false;
+ }
+ if (tag.hasNoTags()) return false;
+ if (!copyable.pasteCopiedData(player, tag)) return false;
+ }
+ return true;
+ }
+
+ private static boolean checkCanLoadConfigurationFromDataStick(NBTTagList list, EntityPlayer player,
+ List<? extends GT_MetaTileEntity_Hatch> hatches) {
+ if (list == null || list.tagList.isEmpty()) return false;
+ List<? extends GT_MetaTileEntity_Hatch> validMTEs = filterValidMTEs(hatches);
+ int end = Math.min(validMTEs.size(), list.tagCount());
+ for (int i = 0; i < end; i++) {
+ GT_MetaTileEntity_Hatch tHatch = validMTEs.get(i);
+ NBTTagCompound tag = list.getCompoundTagAt(i);
+ if (tag.hasNoTags()) continue;
+ if (!(tHatch instanceof IDataCopyable copyable) || !copyable.getCopiedDataIdentifier(player)
+ .equals(tag.getString("type"))) return false;
+ }
+ return true;
+ }
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java
index 11c219aee9..36b20acc55 100644
--- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java
+++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_InputBus_ME.java
@@ -61,6 +61,7 @@ import appeng.util.item.AEItemStack;
import gregtech.api.enums.ItemList;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.IConfigurationCircuitSupport;
+import gregtech.api.interfaces.IDataCopyable;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.modularui.IAddGregtechLogo;
import gregtech.api.interfaces.modularui.IAddUIWidgets;
@@ -80,9 +81,10 @@ import mcp.mobius.waila.api.IWailaDataAccessor;
public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch_InputBus
implements IConfigurationCircuitSupport, IRecipeProcessingAwareHatch, IAddGregtechLogo, IAddUIWidgets,
- IPowerChannelState, ISmartInputHatch {
+ IPowerChannelState, ISmartInputHatch, IDataCopyable {
private static final int SLOT_COUNT = 16;
+ public static final String COPIED_DATA_IDENTIFIER = "stockingBus";
private BaseActionSource requestSource = null;
private @Nullable AENetworkProxy gridProxy = null;
private final ItemStack[] shadowInventory = new ItemStack[SLOT_COUNT];
@@ -318,12 +320,35 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch
ItemStack dataStick = aPlayer.inventory.getCurrentItem();
if (!ItemList.Tool_DataStick.isStackEqual(dataStick, false, true))
return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ);
- if (!dataStick.hasTagCompound() || !"stockingBus".equals(dataStick.stackTagCompound.getString("type")))
- return false;
- NBTTagCompound nbt = dataStick.stackTagCompound;
+ if (!pasteCopiedData(aPlayer, dataStick.stackTagCompound)) return false;
- ItemStack circuit = GT_Utility.loadItem(dataStick.stackTagCompound, "circuit");
+ updateValidGridProxySides();
+ aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.stocking_bus.loaded"));
+ return true;
+ }
+
+ @Override
+ public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
+ if (!(aPlayer instanceof EntityPlayerMP)) return;
+
+ ItemStack dataStick = aPlayer.inventory.getCurrentItem();
+ if (!ItemList.Tool_DataStick.isStackEqual(dataStick, false, true)) return;
+
+ dataStick.stackTagCompound = getCopiedData(aPlayer);
+ dataStick.setStackDisplayName("Stocking Input Bus Configuration");
+ aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.stocking_bus.saved"));
+ }
+
+ @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;
+ ItemStack circuit = GT_Utility.loadItem(nbt, "circuit");
if (GT_Utility.isStackInvalid(circuit)) circuit = null;
if (autoPullAvailable) {
@@ -344,20 +369,13 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch
}
}
setInventorySlotContents(getCircuitSlot(), circuit);
- updateValidGridProxySides();
- aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.stocking_bus.loaded"));
return true;
}
@Override
- public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
- if (!(aPlayer instanceof EntityPlayerMP)) return;
-
- ItemStack dataStick = aPlayer.inventory.getCurrentItem();
- if (!ItemList.Tool_DataStick.isStackEqual(dataStick, false, true)) return;
-
+ public NBTTagCompound getCopiedData(EntityPlayer player) {
NBTTagCompound tag = new NBTTagCompound();
- tag.setString("type", "stockingBus");
+ tag.setString("type", COPIED_DATA_IDENTIFIER);
tag.setBoolean("autoPull", autoPullItemList);
tag.setInteger("minStackSize", minAutoPullStackSize);
tag.setInteger("refreshTime", autoPullRefreshTime);
@@ -372,9 +390,7 @@ public class GT_MetaTileEntity_Hatch_InputBus_ME extends GT_MetaTileEntity_Hatch
}
tag.setTag("itemsToStock", stockingItems);
}
- dataStick.stackTagCompound = tag;
- dataStick.setStackDisplayName("Stocking Input Bus Configuration");
- aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.stocking_bus.saved"));
+ return tag;
}
private int getManualSlot() {
diff --git a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Input_ME.java b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Input_ME.java
index b4266caa47..d59dbb9ce8 100644
--- a/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Input_ME.java
+++ b/src/main/java/gregtech/common/tileentities/machines/GT_MetaTileEntity_Hatch_Input_ME.java
@@ -65,6 +65,7 @@ import appeng.me.helpers.IGridProxyable;
import appeng.util.item.AEFluidStack;
import gregtech.api.enums.ItemList;
import gregtech.api.gui.modularui.GT_UITextures;
+import gregtech.api.interfaces.IDataCopyable;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.modularui.IAddGregtechLogo;
import gregtech.api.interfaces.modularui.IAddUIWidgets;
@@ -81,10 +82,11 @@ import gregtech.api.util.shutdown.ShutDownReasonRegistry;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
-public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_Input
- implements IPowerChannelState, IAddGregtechLogo, IAddUIWidgets, IRecipeProcessingAwareHatch, ISmartInputHatch {
+public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_Input implements IPowerChannelState,
+ IAddGregtechLogo, IAddUIWidgets, IRecipeProcessingAwareHatch, ISmartInputHatch, IDataCopyable {
private static final int SLOT_COUNT = 16;
+ public static final String COPIED_DATA_IDENTIFIER = "stockingHatch";
protected final FluidStack[] storedFluids = new FluidStack[SLOT_COUNT];
protected final FluidStack[] storedInformationFluids = new FluidStack[SLOT_COUNT];
@@ -565,17 +567,13 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In
}
@Override
- public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side,
- float aX, float aY, float aZ) {
- if (!(aPlayer instanceof EntityPlayerMP))
- return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ);
- ItemStack dataStick = aPlayer.inventory.getCurrentItem();
- if (!ItemList.Tool_DataStick.isStackEqual(dataStick, false, true))
- return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ);
- if (!dataStick.hasTagCompound() || !"stockingHatch".equals(dataStick.stackTagCompound.getString("type")))
- return false;
+ public String getCopiedDataIdentifier(EntityPlayer player) {
+ return COPIED_DATA_IDENTIFIER;
+ }
- NBTTagCompound nbt = dataStick.stackTagCompound;
+ @Override
+ public boolean pasteCopiedData(EntityPlayer player, NBTTagCompound nbt) {
+ if (nbt == null || !COPIED_DATA_IDENTIFIER.equals(nbt.getString("type"))) return false;
if (autoPullAvailable) {
setAutoPullFluidList(nbt.getBoolean("autoPull"));
@@ -590,21 +588,13 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In
storedFluids[i] = GT_Utility.loadFluid(stockingFluids.getCompoundTagAt(i));
}
}
-
- updateValidGridProxySides();
- aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.stocking_bus.loaded"));
return true;
}
@Override
- public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
- if (!(aPlayer instanceof EntityPlayerMP)) return;
-
- ItemStack dataStick = aPlayer.inventory.getCurrentItem();
- if (!ItemList.Tool_DataStick.isStackEqual(dataStick, false, true)) return;
-
+ public NBTTagCompound getCopiedData(EntityPlayer player) {
NBTTagCompound tag = new NBTTagCompound();
- tag.setString("type", "stockingHatch");
+ tag.setString("type", COPIED_DATA_IDENTIFIER);
tag.setBoolean("autoPull", autoPullFluidList);
tag.setInteger("minAmount", minAutoPullAmount);
tag.setBoolean("additionalConnection", additionalConnection);
@@ -621,7 +611,33 @@ public class GT_MetaTileEntity_Hatch_Input_ME extends GT_MetaTileEntity_Hatch_In
}
tag.setTag("fluidsToStock", stockingFluids);
}
- dataStick.stackTagCompound = tag;
+ return tag;
+ }
+
+ @Override
+ public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side,
+ float aX, float aY, float aZ) {
+ if (!(aPlayer instanceof EntityPlayerMP))
+ return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ);
+ ItemStack dataStick = aPlayer.inventory.getCurrentItem();
+ if (!ItemList.Tool_DataStick.isStackEqual(dataStick, false, true))
+ return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ);
+
+ if (!pasteCopiedData(aPlayer, dataStick.stackTagCompound)) return false;
+
+ updateValidGridProxySides();
+ aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.stocking_bus.loaded"));
+ return true;
+ }
+
+ @Override
+ public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
+ if (!(aPlayer instanceof EntityPlayerMP)) return;
+
+ ItemStack dataStick = aPlayer.inventory.getCurrentItem();
+ if (!ItemList.Tool_DataStick.isStackEqual(dataStick, false, true)) return;
+
+ dataStick.stackTagCompound = getCopiedData(aPlayer);
dataStick.setStackDisplayName("Stocking Input Hatch Configuration");
aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.machines.stocking_bus.saved"));
}
diff --git a/src/main/java/gregtech/common/tools/GT_Tool_Wrench.java b/src/main/java/gregtech/common/tools/GT_Tool_Wrench.java
index ae9f705b62..fbca109f21 100644
--- a/src/main/java/gregtech/common/tools/GT_Tool_Wrench.java
+++ b/src/main/java/gregtech/common/tools/GT_Tool_Wrench.java
@@ -212,7 +212,6 @@ public class GT_Tool_Wrench extends GT_Tool {
try {
LastEventFromThis = true;
player.setSneaking(true);
-
final MovingObjectPosition movObjPosition = Platform.rayTrace(player, true, false);
if (movObjPosition == null) {
event.setCanceled(true);
diff --git a/src/main/java/net/glease/ggfab/mte/MTE_LinkedInputBus.java b/src/main/java/net/glease/ggfab/mte/MTE_LinkedInputBus.java
index ea39716c1a..7eb625f774 100644
--- a/src/main/java/net/glease/ggfab/mte/MTE_LinkedInputBus.java
+++ b/src/main/java/net/glease/ggfab/mte/MTE_LinkedInputBus.java
@@ -36,6 +36,7 @@ import com.gtnewhorizons.modularui.common.widget.textfield.TextFieldWidget;
import gregtech.api.enums.ItemList;
import gregtech.api.gui.modularui.GT_UITextures;
+import gregtech.api.interfaces.IDataCopyable;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
@@ -47,9 +48,11 @@ import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
import gregtech.common.tileentities.machines.IRecipeProcessingAwareHatch;
-public class MTE_LinkedInputBus extends GT_MetaTileEntity_Hatch_InputBus implements IRecipeProcessingAwareHatch {
+public class MTE_LinkedInputBus extends GT_MetaTileEntity_Hatch_InputBus
+ implements IRecipeProcessingAwareHatch, IDataCopyable {
public static final int SIZE_INVENTORY = 18;
+ public static final String COPIED_DATA_IDENTIFIER = "linkedinputbus";
private SharedInventory mRealInventory;
private final ItemStackHandlerProxy handler = new ItemStackHandlerProxy();
private String mChannel;
@@ -370,6 +373,59 @@ public class MTE_LinkedInputBus extends GT_MetaTileEntity_Hatch_InputBus impleme
}
@Override
+ public NBTTagCompound getCopiedData(EntityPlayer player) {
+ if (getChannel() == null) {
+ return null;
+ }
+ NBTTagCompound tag = new NBTTagCompound();
+ tag.setString("type", COPIED_DATA_IDENTIFIER);
+ tag.setString("channel", getChannel());
+ tag.setTag("circuit", GT_Utility.saveItem(getStackInSlot(getCircuitSlot())));
+ if (isPrivate()) {
+ tag.setLong(
+ "owner1",
+ getBaseMetaTileEntity().getOwnerUuid()
+ .getMostSignificantBits());
+ tag.setLong(
+ "owner2",
+ getBaseMetaTileEntity().getOwnerUuid()
+ .getLeastSignificantBits());
+ }
+ return tag;
+ }
+
+ @Override
+ public boolean pasteCopiedData(EntityPlayer player, NBTTagCompound nbt) {
+ // backwards compat
+ if (nbt == null || (!COPIED_DATA_IDENTIFIER.equals(nbt.getString("ggfab.type"))
+ && !COPIED_DATA_IDENTIFIER.equals(nbt.getString("type")))) {
+ return false;
+ }
+ ItemStack circuit = GT_Utility.loadItem(nbt, "circuit");
+ String channel = nbt.getString("channel");
+ if (GT_Utility.isStackInvalid(circuit)) circuit = null;
+ if ("".equals(channel)) {
+ return false;
+ } else if (circuit != null && getConfigurationCircuits().stream()
+ .noneMatch(circuit::isItemEqual)) {
+ return false;
+ }
+ UUID owner = nbt.hasKey("owner1") ? new UUID(nbt.getLong("owner1"), nbt.getLong("owner2")) : null;
+ if (owner != null && !owner.equals(getBaseMetaTileEntity().getOwnerUuid())) {
+ return false;
+ }
+ setPrivate(owner != null);
+ setChannel(channel);
+ setInventorySlotContents(getCircuitSlot(), circuit);
+ return true;
+ }
+
+ @Override
+ public String getCopiedDataIdentifier(EntityPlayer player) {
+ return COPIED_DATA_IDENTIFIER;
+ }
+
+ @Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side,
float aX, float aY, float aZ) {
if (!(aPlayer instanceof EntityPlayerMP))
@@ -377,7 +433,7 @@ public class MTE_LinkedInputBus extends GT_MetaTileEntity_Hatch_InputBus impleme
ItemStack stick = aPlayer.inventory.getCurrentItem();
if (!ItemList.Tool_DataStick.isStackEqual(stick, false, true))
return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ);
- if (!stick.hasTagCompound() || !"linkedinputbus".equals(stick.stackTagCompound.getString("ggfab.type"))) {
+ if (!stick.hasTagCompound() || !COPIED_DATA_IDENTIFIER.equals(stick.stackTagCompound.getString("ggfab.type"))) {
aPlayer.addChatMessage(new ChatComponentTranslation("ggfab.info.linked_input_bus.no_data"));
return true;
}
@@ -415,22 +471,8 @@ public class MTE_LinkedInputBus extends GT_MetaTileEntity_Hatch_InputBus impleme
aPlayer.addChatMessage(new ChatComponentTranslation("ggfab.info.linked_input_bus.no_channel"));
return;
}
- NBTTagCompound tag = new NBTTagCompound();
- tag.setString("ggfab.type", "linkedinputbus");
- tag.setString("channel", getChannel());
- tag.setTag("circuit", GT_Utility.saveItem(getStackInSlot(getCircuitSlot())));
- if (isPrivate()) {
- tag.setLong(
- "owner1",
- getBaseMetaTileEntity().getOwnerUuid()
- .getMostSignificantBits());
- tag.setLong(
- "owner2",
- getBaseMetaTileEntity().getOwnerUuid()
- .getLeastSignificantBits());
- }
aPlayer.addChatMessage(new ChatComponentTranslation("ggfab.info.linked_input_bus.data_copied", getChannel()));
- stick.stackTagCompound = tag;
+ stick.stackTagCompound = getCopiedData(aPlayer);
stick.setStackDisplayName("Linked Input Bus configuration");
// abuse the title mechanism here. I assure you it will be fine (tm).
GT_Utility.ItemNBT.setBookTitle(stick, "Channel: " + getChannel());