Skip to content

Commit

Permalink
Merge branch 'AE2-Integration' into IIA-dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/gregtech/GT_Mod.java
#	src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_QuantumChest.java
  • Loading branch information
Dimach committed Apr 10, 2020
2 parents d6fd73f + d792754 commit a9b9835
Show file tree
Hide file tree
Showing 4 changed files with 337 additions and 313 deletions.
9 changes: 4 additions & 5 deletions src/main/java/gregtech/GT_Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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_DigitalChestBase;
import gregtech.loaders.load.GT_CoverBehaviorLoader;
import gregtech.loaders.load.GT_FuelLoader;
import gregtech.loaders.load.GT_ItemIterator;
Expand Down Expand Up @@ -299,7 +299,7 @@ public void onPreLoad(FMLPreInitializationEvent aEvent) {
gregtechproxy.mHardRadonRecipe = tMainConfig.get("general","HardRadonRecipe",false).getBoolean(false);
gregtechproxy.disassemblerRecipeMapOn = tMainConfig.get("general","DisasssemblerRecipeMapEnabled", true).getBoolean(true);
gregtechproxy.enableFixQuestsCommand = tMainConfig.get("general", "EnableUpdateQuestsCommand", false).getBoolean(false);
gregtechproxy.mEasyEnderIOMaterialsRecipe = tMainConfig.get("general","EasyEnderIOMaterialsRecipe",false).getBoolean(false);
gregtechproxy.mEasyEnderIOMaterialsRecipe = tMainConfig.get("general","EasyEnderIOMaterialsRecipe",false).getBoolean(false);
GT_LanguageManager.i18nPlaceholder = tMainConfig.get("general", "UsePlaceholderForMaterialNamesInLangFile", true).getBoolean(true);

Materials[] tDisableOres = new Materials[]{Materials.Chrome, Materials.Naquadria, Materials.Silicon, Materials.Cobalt, Materials.Cadmium, Materials.Indium, Materials.Tungsten,
Expand Down Expand Up @@ -728,7 +728,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) {
}
}
if (Loader.isModLoaded(MOD_ID_AE)) {
GT_MetaTileEntity_QuantumChest.registerAEIntegration();
GT_MetaTileEntity_DigitalChestBase.registerAEIntegration();
}
String tName = "";
if (GregTech_API.sRecipeFile.get(ConfigCategories.Recipes.disabledrecipes, aTextIC2 + (tName = "blastfurnace"), true)) {
Expand Down Expand Up @@ -886,7 +886,6 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) {
GT_Recipe.GT_Recipe_Map.sReplicatorFakeRecipes.addFakeRecipe(false, null, ISmat0, ISmat1, new FluidStack[]{Materials.UUMatter.getFluid(tMaterial.getMass())}, null, (int) (tMaterial.getMass() * 512L), 32, 0);
}
}

}
GT_Recipe.GT_Recipe_Map.sOrganicReplicatorFakeRecipes.addFakeRecipe(false,(new ItemStack[]{ItemList.IC2_Crop_Seeds.getWithName(1,"Instance seeds to duplicate(does not get consumed in progress)",new Object[0])}),(new ItemStack[]{ItemList.IC2_Crop_Seeds.getWithName(1,"Duplicated seeds; Chance equals efficiency")}),null, (new FluidStack[]{Materials.UUMatter.getFluid(1L)}),null,200,32,0);
if (!GT_MetaTileEntity_Massfabricator.sRequiresUUA) GT_Recipe.GT_Recipe_Map.sMassFabFakeRecipes.addFakeRecipe(false, null, null, null, null, new FluidStack[]{Materials.UUMatter.getFluid(1L)}, GT_MetaTileEntity_Massfabricator.sDurationMultiplier, 256, 0);
Expand All @@ -905,7 +904,7 @@ public void onPostLoad(FMLPostInitializationEvent aEvent) {

addSolidFakeLargeBoilerFuels();
GT_Recipe.GT_Recipe_Map_Disassembler.initCachedRecipes();

achievements = new GT_Achievements();
GT_Log.out.println("GT_Mod: Loading finished, deallocating temporary Init Variables.");
GregTech_API.sBeforeGTPreload = null;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/gregtech/api/objects/AE2DigitalChestHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gregtech.api.objects;

import cpw.mods.fml.common.Optional;
import gregtech.api.metatileentity.BaseMetaTileEntity;
import gregtech.common.tileentities.storage.GT_MetaTileEntity_DigitalChestBase;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;

@Optional.Interface(iface = "appeng.api.storage.IExternalStorageHandler", modid = "appliedenergistics2", striprefs = true)
public class AE2DigitalChestHandler implements appeng.api.storage.IExternalStorageHandler {

@Optional.Method(modid = "appliedenergistics2")
public boolean canHandle(final TileEntity te, final ForgeDirection d, final appeng.api.storage.StorageChannel chan, final appeng.api.networking.security.BaseActionSource mySrc) {
return chan == appeng.api.storage.StorageChannel.ITEMS && te instanceof BaseMetaTileEntity && ((BaseMetaTileEntity) te).getMetaTileEntity() instanceof GT_MetaTileEntity_DigitalChestBase;
}

@Optional.Method(modid = "appliedenergistics2")
public appeng.api.storage.IMEInventory getInventory(final TileEntity te, final ForgeDirection d, final appeng.api.storage.StorageChannel chan, final appeng.api.networking.security.BaseActionSource src) {
if (chan == appeng.api.storage.StorageChannel.ITEMS) {
return new appeng.me.storage.MEMonitorIInventory(new appeng.util.inv.IMEAdaptor((GT_MetaTileEntity_DigitalChestBase) (((BaseMetaTileEntity) te).getMetaTileEntity()), src));
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
package gregtech.common.tileentities.storage;

import cpw.mods.fml.common.Optional;
import gregtech.api.enums.Textures;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock;
import gregtech.api.objects.AE2DigitalChestHandler;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_Utility;
import gregtech.common.gui.GT_Container_QuantumChest;
import gregtech.common.gui.GT_GUIContainer_QuantumChest;
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.util.EnumChatFormatting;

@Optional.Interface(iface = "appeng.api.storage.IMEInventory", modid = "appliedenergistics2")
public abstract class GT_MetaTileEntity_DigitalChestBase extends GT_MetaTileEntity_TieredMachineBlock implements appeng.api.storage.IMEInventory<appeng.api.storage.data.IAEItemStack> {
public GT_MetaTileEntity_DigitalChestBase(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 3, "This Chest stores " + CommonSizeCompute(aTier) + " Blocks");
}

public GT_MetaTileEntity_DigitalChestBase(String aName, int aTier, String aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 3, aDescription, aTextures);
}

public GT_MetaTileEntity_DigitalChestBase(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 3, aDescription, aTextures);
}

@Override
public boolean isSimpleMachine() {
return true;
}

@Override
public boolean isFacingValid(byte aFacing) {
return true;
}

@Override
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}

@Override
public boolean isValidSlot(int aIndex) {
return true;
}

@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
if (aBaseMetaTileEntity.isClientSide()) return true;
aBaseMetaTileEntity.openGUI(aPlayer);
return true;
}

@Override
public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
return new GT_Container_QuantumChest(aPlayerInventory, aBaseMetaTileEntity);
}

@Override
public Object getClientGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) {
return new GT_GUIContainer_QuantumChest(aPlayerInventory, aBaseMetaTileEntity, getLocalName());
}

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {

if (getBaseMetaTileEntity().isServerSide() && getBaseMetaTileEntity().isAllowedToWork()) {
if ((getItemCount() <= 0)) {
setItemStack(null);
setItemCount(0);
}
if (getItemStack() == null && mInventory[0] != null) {
setItemStack(mInventory[0].copy());
}
int count = getItemCount();
ItemStack stack = getItemStack();
if ((mInventory[0] != null) && (count < getMaxItemCount()) && GT_Utility.areStacksEqual(mInventory[0], stack)) {
count += mInventory[0].stackSize;
if (count > getMaxItemCount()) {
mInventory[0].stackSize = (count - getMaxItemCount());
count = getMaxItemCount();
} else {
mInventory[0] = null;
}
}
if (mInventory[1] == null && stack != null) {
mInventory[1] = stack.copy();
mInventory[1].stackSize = Math.min(stack.getMaxStackSize(), count);
count -= mInventory[1].stackSize;
} else if ((count > 0) && GT_Utility.areStacksEqual(mInventory[1], stack) && mInventory[1].getMaxStackSize() > mInventory[1].stackSize) {
int tmp = Math.min(count, mInventory[1].getMaxStackSize() - mInventory[1].stackSize);
mInventory[1].stackSize += tmp;
count -= tmp;
}
setItemCount(count);
if (stack != null) {
mInventory[2] = stack.copy();
mInventory[2].stackSize = Math.min(stack.getMaxStackSize(), count);
} else {
mInventory[2] = null;
}
}
}

abstract protected int getItemCount();
abstract public void setItemCount(int aCount);
abstract protected ItemStack getItemStack();
abstract protected void setItemStack(ItemStack s);

@Override
public int getProgresstime() {
return getItemCount() + (mInventory[0] == null ? 0 : mInventory[0].stackSize) + (mInventory[1] == null ? 0 : mInventory[1].stackSize);
}

@Override
public int maxProgresstime() {
return getMaxItemCount();
}

protected static int CommonSizeCompute(int tier){
switch(tier){
case 1:
return 4000000;
case 2:
return 8000000;
case 3:
return 16000000;
case 4:
return 32000000;
case 5:
return 64000000;
case 6:
return 128000000;
case 7:
return 256000000;
case 8:
return 512000000;
case 9:
return 1024000000;
case 10:
return 2147483640;
default:
return 0;
}
}

@Override
public int getMaxItemCount() {
return CommonSizeCompute(mTier);
}

@Override
public boolean allowPullStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
return aIndex == 1;
}

@Override
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
return aIndex == 0 && (mInventory[0] == null || GT_Utility.areStacksEqual(mInventory[0], aStack));
}

abstract protected String chestName();

@Optional.Method(modid = "appliedenergistics2")
public static void registerAEIntegration() {
appeng.api.AEApi.instance().registries().externalStorage().addExternalStorageInterface(new AE2DigitalChestHandler());
}

@Override
public boolean isGivingInformation() {
return true;
}

@Override
public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setInteger("mItemCount", getItemCount());
if (getItemStack() != null)
aNBT.setTag("mItemStack", getItemStack().writeToNBT(new NBTTagCompound()));
}

@Override
public void loadNBTData(NBTTagCompound aNBT) {
if (aNBT.hasKey("mItemCount"))
setItemCount(aNBT.getInteger("mItemCount"));
if (aNBT.hasKey("mItemStack"))
setItemStack(ItemStack.loadItemStackFromNBT((NBTTagCompound) aNBT.getTag("mItemStack")));
}

@Override
public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) {
if (aBaseMetaTileEntity.getFrontFacing() == 0 && aSide == 4) {
return new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_QCHEST)};
}
return aSide == aBaseMetaTileEntity.getFrontFacing() ? new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1], new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_QCHEST)} : new ITexture[]{Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex + 1]};//aSide != aFacing ? mMachineBlock != 0 ? new ITexture[] {Textures.BlockIcons.CASING_BLOCKS[mMachineBlock]} : new ITexture[] {Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex+1]} : mMachineBlock != 0 ? aActive ? getTexturesActive(Textures.BlockIcons.CASING_BLOCKS[mMachineBlock]) : getTexturesInactive(Textures.BlockIcons.CASING_BLOCKS[mMachineBlock]) : aActive ? getTexturesActive(Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex+1]) : getTexturesInactive(Textures.BlockIcons.MACHINE_CASINGS[mTier][aColorIndex+1]);
}

@Override
public ITexture[][][] getTextureSet(ITexture[] aTextures) {
return new ITexture[0][0][0];
}

@Override
public String[] getInfoData() {

if (getItemStack() == null) {
return new String[]{
EnumChatFormatting.RESET + chestName() + EnumChatFormatting.RESET,
"Stored Items:",
EnumChatFormatting.RED + "0" + EnumChatFormatting.RESET,
"Total Items:",
EnumChatFormatting.YELLOW + Integer.toString(getMaxItemCount()) + EnumChatFormatting.RESET
};
}
return new String[]{
EnumChatFormatting.RESET + chestName() + EnumChatFormatting.RESET,
"Stored Items:",
EnumChatFormatting.GREEN + Integer.toString(getItemCount()) + EnumChatFormatting.RESET,
"Total Items:",
EnumChatFormatting.YELLOW + Integer.toString(getMaxItemCount()) + EnumChatFormatting.RESET
};
}

@Optional.Method(modid = "appliedenergistics2")
public appeng.api.storage.data.IAEItemStack injectItems(final appeng.api.storage.data.IAEItemStack input, final appeng.api.config.Actionable mode, final appeng.api.networking.security.BaseActionSource src) {
final ItemStack inputStack = input.getItemStack();
if (inputStack == null)
return null;
ItemStack storedStack = getItemStack();
if (storedStack != null) {
if (GT_Utility.areStacksEqual(storedStack, inputStack)) {
if (input.getStackSize() + getItemCount() > getMaxItemCount())
return createOverflowStack(input.getStackSize() + getItemCount(), mode);
else {
if (mode != appeng.api.config.Actionable.SIMULATE)
setItemCount(getItemCount() + (int) input.getStackSize());
}
return null;
} else
return input;
} else {
if (mode != appeng.api.config.Actionable.SIMULATE)
setItemStack(inputStack.copy());
if (input.getStackSize() > getMaxItemCount())
return createOverflowStack(input.getStackSize(), mode);
else if (mode != appeng.api.config.Actionable.SIMULATE)
setItemCount((int) input.getStackSize());
return null;
}
}

@Optional.Method(modid = "appliedenergistics2")
private appeng.api.storage.data.IAEItemStack createOverflowStack(long size, appeng.api.config.Actionable mode) {
final appeng.api.storage.data.IAEItemStack overflow = appeng.util.item.AEItemStack.create(getItemStack());
overflow.setStackSize(size - getMaxItemCount());
if (mode != appeng.api.config.Actionable.SIMULATE)
setItemCount(getMaxItemCount());
return overflow;
}

@Optional.Method(modid = "appliedenergistics2")
public appeng.api.storage.data.IAEItemStack extractItems(final appeng.api.storage.data.IAEItemStack request, final appeng.api.config.Actionable mode, final appeng.api.networking.security.BaseActionSource src) {
if (request.equals(getItemStack())) {
if (request.getStackSize() >= getItemCount()) {
appeng.util.item.AEItemStack result = appeng.util.item.AEItemStack.create(getItemStack());
result.setStackSize(getItemCount());
if (mode != appeng.api.config.Actionable.SIMULATE)
setItemCount(0);
return result;
} else {
if (mode != appeng.api.config.Actionable.SIMULATE)
setItemCount(getItemCount() - (int) request.getStackSize());
return request.copy();
}
}
return null;
}

@Optional.Method(modid = "appliedenergistics2")
public appeng.api.storage.StorageChannel getChannel() {
return appeng.api.storage.StorageChannel.ITEMS;
}

@Optional.Method(modid = "appliedenergistics2")
public appeng.api.storage.data.IItemList<appeng.api.storage.data.IAEItemStack> getAvailableItems(final appeng.api.storage.data.IItemList<appeng.api.storage.data.IAEItemStack> out) {
ItemStack storedStack = getItemStack();
if (storedStack != null) {
appeng.util.item.AEItemStack s = appeng.util.item.AEItemStack.create(storedStack);
s.setStackSize(getItemCount());
out.add(s);
}
return out;
}
}
Loading

0 comments on commit a9b9835

Please sign in to comment.