aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/gregtech/GT_Mod.java8
-rw-r--r--src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_QuantumChest.java101
-rw-r--r--src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_SuperChest.java101
3 files changed, 207 insertions, 3 deletions
diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java
index 4d826440b0..6285dbd11a 100644
--- a/src/main/java/gregtech/GT_Mod.java
+++ b/src/main/java/gregtech/GT_Mod.java
@@ -23,6 +23,8 @@ import gregtech.common.items.GT_MetaGenerated_Tool_01;
import gregtech.common.items.armor.components.LoadArmorComponents;
import gregtech.common.items.behaviors.Behaviour_DataOrb;
import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Massfabricator;
+import gregtech.common.tileentities.storage.GT_MetaTileEntity_QuantumChest;
+import gregtech.common.tileentities.storage.GT_MetaTileEntity_SuperChest;
import gregtech.loaders.load.GT_CoverBehaviorLoader;
import gregtech.loaders.load.GT_FuelLoader;
import gregtech.loaders.load.GT_ItemIterator;
@@ -62,6 +64,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import static gregtech.api.enums.GT_Values.MOD_ID_AE;
import static gregtech.api.enums.GT_Values.MOD_ID_FR;
@Mod(modid = "gregtech", name = "GregTech", version = "MC1710", useMetadata = false,
@@ -810,7 +813,10 @@ public class GT_Mod implements IGT_Mod {
GT_Forestry_Compat.transferCentrifugeRecipes();
GT_Forestry_Compat.transferSqueezerRecipes();
}
-
+ if (Loader.isModLoaded(MOD_ID_AE)) {
+ GT_MetaTileEntity_QuantumChest.registerAEIntegration();
+ GT_MetaTileEntity_SuperChest.registerAEIntegration();
+ }
String tName = "";
if (GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.disabledrecipes, aTextIC2 + (tName = "blastfurnace"), true)) {
GT_ModHandler.removeRecipeByOutput(GT_ModHandler.getIC2Item(tName, 1L));
diff --git a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_QuantumChest.java b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_QuantumChest.java
index 5ab451bb03..5887faeb27 100644
--- a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_QuantumChest.java
+++ b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_QuantumChest.java
@@ -1,8 +1,18 @@
package gregtech.common.tileentities.storage;
+import appeng.api.config.Actionable;
+import appeng.api.networking.security.BaseActionSource;
+import appeng.api.storage.IMEInventory;
+import appeng.api.storage.StorageChannel;
+import appeng.api.storage.data.IAEItemStack;
+import appeng.api.storage.data.IItemList;
+import appeng.me.storage.MEMonitorIInventory;
+import appeng.util.inv.IMEAdaptor;
+import appeng.util.item.AEItemStack;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.BaseMetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock;
import gregtech.api.objects.GT_RenderedTexture;
@@ -13,9 +23,13 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
+import appeng.api.AEApi;
+import appeng.api.storage.IExternalStorageHandler;
+import net.minecraftforge.common.util.ForgeDirection;
-public class GT_MetaTileEntity_QuantumChest extends GT_MetaTileEntity_TieredMachineBlock {
+public class GT_MetaTileEntity_QuantumChest extends GT_MetaTileEntity_TieredMachineBlock implements IMEInventory<IAEItemStack> {
public int mItemCount = 0;
public ItemStack mItemStack = null;
public GT_MetaTileEntity_QuantumChest(int aID, String aName, String aNameRegional, int aTier) {
@@ -210,4 +224,89 @@ public class GT_MetaTileEntity_QuantumChest extends GT_MetaTileEntity_TieredMach
public ITexture[][][] getTextureSet(ITexture[] aTextures) {
return new ITexture[0][0][0];
}
+ @Override
+ public IAEItemStack injectItems(final IAEItemStack input, final Actionable mode, final BaseActionSource src ) {
+ final ItemStack inputStack = input.getItemStack();
+ if (inputStack == null)
+ return null;
+ if (mItemStack != null) {
+ if (GT_Utility.areStacksEqual(mItemStack, inputStack)) {
+ if (input.getStackSize() + mItemCount > getMaxItemCount())
+ return createOverflowStack(input.getStackSize() + mItemCount, mode);
+ else
+ mItemCount += input.getStackSize();
+ return null;
+ } else
+ return input;
+ } else {
+ if (mode == Actionable.MODULATE)
+ mItemStack = inputStack.copy();
+ if (input.getStackSize() > getMaxItemCount())
+ return createOverflowStack(input.getStackSize(), mode);
+ else if (mode == Actionable.MODULATE)
+ mItemCount = (int) input.getStackSize();
+ return null;
+ }
+ }
+
+ private IAEItemStack createOverflowStack(long size, Actionable mode) {
+ final IAEItemStack overflow = AEItemStack.create(mItemStack);
+ overflow.setStackSize(size - getMaxItemCount());
+ if (mode == Actionable.MODULATE)
+ mItemCount = getMaxItemCount();
+ return overflow;
+ }
+
+ @Override
+ public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final BaseActionSource src ) {
+ if (request.equals(mItemStack)) {
+ if (request.getStackSize() >= mItemCount) {
+ AEItemStack result = AEItemStack.create(mItemStack);
+ result.setStackSize(mItemCount);
+ if (mode == Actionable.MODULATE)
+ mItemCount = 0;
+ return result;
+ } else {
+ if (mode == Actionable.MODULATE)
+ mItemCount -= (int) request.getStackSize();
+ return request.copy();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public StorageChannel getChannel()
+ {
+ return StorageChannel.ITEMS;
+ }
+
+ @Override
+ public IItemList<IAEItemStack> getAvailableItems(final IItemList<IAEItemStack> out )
+ {
+ if (mItemStack != null) {
+ AEItemStack s = AEItemStack.create(mItemStack);
+ s.setStackSize(mItemCount);
+ out.add(s);
+ }
+ return out;
+ }
+
+ static class AEHandler implements IExternalStorageHandler
+ {
+ @Override
+ public boolean canHandle(final TileEntity te, final ForgeDirection d, final StorageChannel chan, final BaseActionSource mySrc )
+ {
+ return chan == StorageChannel.ITEMS && te instanceof BaseMetaTileEntity && ((BaseMetaTileEntity)te).getMetaTileEntity() instanceof GT_MetaTileEntity_QuantumChest;
+ }
+ public IMEInventory getInventory(final TileEntity te, final ForgeDirection d, final StorageChannel chan, final BaseActionSource src ) {
+ if (chan == StorageChannel.ITEMS) {
+ return new MEMonitorIInventory( new IMEAdaptor( (GT_MetaTileEntity_QuantumChest)(((BaseMetaTileEntity)te).getMetaTileEntity()), src));
+ }
+ return null;
+ }
+ }
+ public static void registerAEIntegration() {
+ AEApi.instance().registries().externalStorage().addExternalStorageInterface( new AEHandler() );
+ }
}
diff --git a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_SuperChest.java b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_SuperChest.java
index 5b4e5549c3..aaa1913942 100644
--- a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_SuperChest.java
+++ b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_SuperChest.java
@@ -1,8 +1,20 @@
package gregtech.common.tileentities.storage;
+import appeng.api.AEApi;
+import appeng.api.config.Actionable;
+import appeng.api.networking.security.BaseActionSource;
+import appeng.api.storage.IExternalStorageHandler;
+import appeng.api.storage.IMEInventory;
+import appeng.api.storage.StorageChannel;
+import appeng.api.storage.data.IAEItemStack;
+import appeng.api.storage.data.IItemList;
+import appeng.me.storage.MEMonitorIInventory;
+import appeng.util.inv.IMEAdaptor;
+import appeng.util.item.AEItemStack;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.BaseMetaTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock;
import gregtech.api.objects.GT_RenderedTexture;
@@ -13,9 +25,11 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
+import net.minecraftforge.common.util.ForgeDirection;
-public class GT_MetaTileEntity_SuperChest extends GT_MetaTileEntity_TieredMachineBlock {
+public class GT_MetaTileEntity_SuperChest extends GT_MetaTileEntity_TieredMachineBlock implements IMEInventory<IAEItemStack> {
public int mItemCount = 0;
public ItemStack mItemStack = null;
public GT_MetaTileEntity_SuperChest(int aID, String aName, String aNameRegional, int aTier) {
@@ -247,4 +261,89 @@ public class GT_MetaTileEntity_SuperChest extends GT_MetaTileEntity_TieredMachin
public ITexture[][][] getTextureSet(ITexture[] aTextures) {
return new ITexture[0][0][0];
}
+ @Override
+ public IAEItemStack injectItems(final IAEItemStack input, final Actionable mode, final BaseActionSource src ) {
+ final ItemStack inputStack = input.getItemStack();
+ if (inputStack == null)
+ return null;
+ if (mItemStack != null) {
+ if (GT_Utility.areStacksEqual(mItemStack, inputStack)) {
+ if (input.getStackSize() + mItemCount > getMaxItemCount())
+ return createOverflowStack(input.getStackSize() + mItemCount, mode);
+ else
+ mItemCount += input.getStackSize();
+ return null;
+ } else
+ return input;
+ } else {
+ if (mode == Actionable.MODULATE)
+ mItemStack = inputStack.copy();
+ if (input.getStackSize() > getMaxItemCount())
+ return createOverflowStack(input.getStackSize(), mode);
+ else if (mode == Actionable.MODULATE)
+ mItemCount = (int) input.getStackSize();
+ return null;
+ }
+ }
+
+ private IAEItemStack createOverflowStack(long size, Actionable mode) {
+ final IAEItemStack overflow = AEItemStack.create(mItemStack);
+ overflow.setStackSize(size - getMaxItemCount());
+ if (mode == appeng.api.config.Actionable.MODULATE)
+ mItemCount = getMaxItemCount();
+ return overflow;
+ }
+
+ @Override
+ public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final BaseActionSource src ) {
+ if (request.equals(mItemStack)) {
+ if (request.getStackSize() >= mItemCount) {
+ AEItemStack result = AEItemStack.create(mItemStack);
+ result.setStackSize(mItemCount);
+ if (mode == appeng.api.config.Actionable.MODULATE)
+ mItemCount = 0;
+ return result;
+ } else {
+ if (mode == appeng.api.config.Actionable.MODULATE)
+ mItemCount -= (int) request.getStackSize();
+ return request.copy();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public StorageChannel getChannel()
+ {
+ return StorageChannel.ITEMS;
+ }
+
+ @Override
+ public IItemList<IAEItemStack> getAvailableItems(final IItemList<IAEItemStack> out )
+ {
+ if (mItemStack != null) {
+ AEItemStack s = AEItemStack.create(mItemStack);
+ s.setStackSize(mItemCount);
+ out.add(s);
+ }
+ return out;
+ }
+
+ static class AEHandler implements IExternalStorageHandler
+ {
+ @Override
+ public boolean canHandle(final TileEntity te, final ForgeDirection d, final StorageChannel chan, final BaseActionSource mySrc )
+ {
+ return chan == StorageChannel.ITEMS && te instanceof BaseMetaTileEntity && ((BaseMetaTileEntity)te).getMetaTileEntity() instanceof GT_MetaTileEntity_SuperChest;
+ }
+ public IMEInventory getInventory(final TileEntity te, final ForgeDirection d, final StorageChannel chan, final BaseActionSource src ) {
+ if (chan == StorageChannel.ITEMS) {
+ return new MEMonitorIInventory( new IMEAdaptor( (GT_MetaTileEntity_SuperChest)(((BaseMetaTileEntity)te).getMetaTileEntity()), src));
+ }
+ return null;
+ }
+ }
+ public static void registerAEIntegration() {
+ AEApi.instance().registries().externalStorage().addExternalStorageInterface( new GT_MetaTileEntity_SuperChest.AEHandler() );
+ }
}