aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/metatileentity
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/metatileentity')
-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
2 files changed, 57 insertions, 11 deletions
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;
}