diff options
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity')
4 files changed, 141 insertions, 22 deletions
diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/BaseCustomTileEntity.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/BaseCustomTileEntity.java index f6bec1f402..6967c8eb33 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/BaseCustomTileEntity.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/BaseCustomTileEntity.java @@ -1,7 +1,9 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; +import java.util.Random; import gregtech.GT_Mod; import gregtech.api.GregTech_API; @@ -9,19 +11,39 @@ import gregtech.api.enums.GT_Values; import gregtech.api.metatileentity.BaseMetaTileEntity; import gregtech.api.util.GT_Log; import gregtech.api.util.GT_Utility; -import gregtech.common.GT_Pollution; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.minecraft.gregtech.PollutionUtils; import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; +import gtPlusPlus.xmod.gregtech.common.StaticFields59; import ic2.api.Direction; +import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; public class BaseCustomTileEntity extends BaseMetaTileEntity { protected NBTTagCompound mRecipeStuff2; + private static final Field ENTITY_ITEM_HEALTH_FIELD_2; + + static { + Field f = null; + try { + f = EntityItem.class.getDeclaredField("field_70291_e"); + f.setAccessible(true); + } catch (Exception var4) { + try { + f = EntityItem.class.getDeclaredField("health"); + f.setAccessible(true); + } catch (Exception var3) { + var4.printStackTrace(); + var3.printStackTrace(); + } + } + + ENTITY_ITEM_HEALTH_FIELD_2 = f; + } public BaseCustomTileEntity() { super(); @@ -74,7 +96,14 @@ public class BaseCustomTileEntity extends BaseMetaTileEntity { this.mReleaseEnergy = false; this.mMetaTileEntity.onExplosion(); int i; - if (GT_Mod.gregtechproxy.mExplosionItemDrop) { + + boolean aExplosionDropItem = false; + Object aProxyField = StaticFields59.getFieldFromGregtechProxy(false, "mExplosionItemDrop"); + if (boolean.class.isInstance(aProxyField) || Boolean.class.isInstance(aProxyField)) { + aExplosionDropItem = (boolean) aProxyField; + } + + if (aExplosionDropItem) { for (i = 0; i < this.getSizeInventory(); ++i) { ItemStack tItem = this.getStackInSlot(i); if (tItem != null && tItem.stackSize > 0 && this.isValidSlot(i)) { @@ -95,6 +124,38 @@ public class BaseCustomTileEntity extends BaseMetaTileEntity { } } + + + public void dropItems(ItemStack tItem) { + if (tItem != null) { + Random tRandom = new Random(); + EntityItem tItemEntity = new EntityItem(this.worldObj, + (double) ((float) this.xCoord + tRandom.nextFloat() * 0.8F + 0.1F), + (double) ((float) this.yCoord + tRandom.nextFloat() * 0.8F + 0.1F), + (double) ((float) this.zCoord + tRandom.nextFloat() * 0.8F + 0.1F), + new ItemStack(tItem.getItem(), tItem.stackSize, tItem.getItemDamage())); + if (tItem.hasTagCompound()) { + tItemEntity.getEntityItem().setTagCompound((NBTTagCompound) tItem.getTagCompound().copy()); + } + + tItemEntity.motionX = tRandom.nextGaussian() * 0.0500000007450581D; + tItemEntity.motionY = tRandom.nextGaussian() * 0.0500000007450581D + 0.2000000029802322D; + tItemEntity.motionZ = tRandom.nextGaussian() * 0.0500000007450581D; + tItemEntity.hurtResistantTime = 999999; + tItemEntity.lifespan = 60000; + + try { + if (ENTITY_ITEM_HEALTH_FIELD_2 != null) { + ENTITY_ITEM_HEALTH_FIELD_2.setInt(tItemEntity, 99999999); + } + } catch (Exception var5) { + ; + } + + this.worldObj.spawnEntityInWorld(tItemEntity); + tItem.stackSize = 0; + } + } public ArrayList<ItemStack> getDrops() { ArrayList<ItemStack> aDrops = new ArrayList<ItemStack>(); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicMachine.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicMachine.java index 19ba932a02..2eb1d36791 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicMachine.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/custom/power/GTPP_MTE_BasicMachine.java @@ -11,11 +11,11 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.GT_RenderedTexture; -import gregtech.api.objects.XSTR; import gregtech.api.util.GT_OreDictUnificator; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.random.XSTR; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java index d9e2692b09..752321506d 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_TurbineProvider.java @@ -31,11 +31,11 @@ public class GT_MetaTileEntity_Hatch_TurbineProvider extends GT_MetaTileEntity_H } public GT_MetaTileEntity_Hatch_TurbineProvider(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) { - super(aName, aTier, aDescription, aTextures); + super(aName, aTier, aDescription[0], aTextures); } public MetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) { - return new GT_MetaTileEntity_Hatch_TurbineProvider(this.mName, this.mTier, this.mDescriptionArray, this.mTextures); + return new GT_MetaTileEntity_Hatch_TurbineProvider(this.mName, this.mTier, this.mDescription, this.mTextures); } public Object getServerGUI(int aID, InventoryPlayer aPlayerInventory, IGregTechTileEntity aBaseMetaTileEntity) { diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java index 827091301b..4a6cad20c3 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMeta_MultiBlockBase.java @@ -6,6 +6,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; @@ -40,14 +41,15 @@ import gregtech.api.util.GT_Recipe.GT_Recipe_Map; import gregtech.api.util.GT_Utility; import gtPlusPlus.GTplusplus; import gtPlusPlus.GTplusplus.INIT_PHASE; +import gtPlusPlus.api.helpers.GregtechPlusPlus_API.Multiblock_API; import gtPlusPlus.api.objects.Logger; import gtPlusPlus.api.objects.data.AutoMap; import gtPlusPlus.api.objects.data.ConcurrentHashSet; import gtPlusPlus.api.objects.data.ConcurrentSet; import gtPlusPlus.api.objects.data.FlexiblePair; -import gtPlusPlus.api.objects.data.Pair; import gtPlusPlus.api.objects.data.Triplet; import gtPlusPlus.api.objects.minecraft.BlockPos; +import gtPlusPlus.api.objects.minecraft.multi.SpecialMultiBehaviour; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.LoadedMods; import gtPlusPlus.core.recipe.common.CI; @@ -65,7 +67,6 @@ import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEn import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_InputBattery; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_OutputBattery; import gtPlusPlus.xmod.gregtech.api.objects.MultiblockRequirements; - import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -78,14 +79,10 @@ import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; -public abstract class GregtechMeta_MultiBlockBase -extends -GT_MetaTileEntity_MultiBlockBase { - +public abstract class GregtechMeta_MultiBlockBase extends GT_MetaTileEntity_MultiBlockBase { public static final boolean DEBUG_DISABLE_CORES_TEMPORARILY = true; - static { Method a08 = findRecipe08 = ReflectionUtils.getMethod(GT_Recipe_Map.class, "findRecipe", IHasWorldObjectAndCoords.class, GT_Recipe.class, boolean.class, long.class, FluidStack[].class, ItemStack.class, ItemStack[].class); @@ -102,11 +99,10 @@ GT_MetaTileEntity_MultiBlockBase { try { calculatePollutionReduction = GT_MetaTileEntity_Hatch_Muffler.class.getDeclaredMethod("calculatePollutionReduction", int.class); - } catch (NoSuchMethodException | SecurityException e) {} - - - //gregtech.api.util.GT_Recipe.GT_Recipe_Map.findRecipe(IHasWorldObjectAndCoords, GT_Recipe, boolean, long, FluidStack[], ItemStack, ItemStack...) + } catch (NoSuchMethodException | SecurityException e) {} + mCustomBehviours = new HashMap<String, SpecialMultiBehaviour>(); + } //Find Recipe Methods @@ -124,6 +120,10 @@ GT_MetaTileEntity_MultiBlockBase { public ArrayList<GT_MetaTileEntity_Hatch_InputBattery> mChargeHatches = new ArrayList<GT_MetaTileEntity_Hatch_InputBattery>(); public ArrayList<GT_MetaTileEntity_Hatch_OutputBattery> mDischargeHatches = new ArrayList<GT_MetaTileEntity_Hatch_OutputBattery>(); + // Custom Behaviour Map + private static final HashMap<String, SpecialMultiBehaviour> mCustomBehviours; + + public GregtechMeta_MultiBlockBase(final int aID, final String aName, final String aNameRegional) { super(aID, aName, aNameRegional); @@ -471,15 +471,30 @@ GT_MetaTileEntity_MultiBlockBase { public String getSound() { return ""; } + public boolean canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes) { + return canBufferOutputs(aRecipe, aParallelRecipes, true); + } + + public boolean canBufferOutputs(final GT_Recipe aRecipe, int aParallelRecipes, boolean aAllow16SlotWithoutCheck) { Logger.INFO("Determining if we have space to buffer outputs. Parallel: "+aParallelRecipes); // Null recipe or a recipe with lots of outputs? // E.G. Gendustry custom comb with a billion centrifuge outputs? - // Do it anyway. + // Do it anyway, provided the multi allows it. Default behaviour is aAllow16SlotWithoutCheck = true. if (aRecipe == null || aRecipe.mOutputs.length > 16) { - return aRecipe == null ? false : true; + if (aRecipe == null) { + return false; + } + else if (aRecipe.mOutputs.length > 16) { + if (aAllow16SlotWithoutCheck) { + return true; + } + else { + // Do nothing, we want to check this recipe properly. + } + } } // Do we even need to check for item outputs? @@ -999,12 +1014,11 @@ GT_MetaTileEntity_MultiBlockBase { byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage)); long tEnergy = getMaxInputEnergy(); log("Running checkRecipeGeneric(0)"); - - + GT_Recipe tRecipe = findRecipe( getBaseMetaTileEntity(), mLastRecipe, false, - gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); - + gregtech.api.enums.GT_Values.V[tTier], aFluidInputs, aItemInputs); + log("Running checkRecipeGeneric(1)"); // Remember last recipe - an optimization for findRecipe() this.mLastRecipe = tRecipe; @@ -1013,6 +1027,50 @@ GT_MetaTileEntity_MultiBlockBase { log("BAD RETURN - 1"); return false; } + + + /* + * Check for Special Behaviours + */ + + // First populate the map if we need to. + if (mCustomBehviours == null || mCustomBehviours.isEmpty()) { + mCustomBehviours.putAll(Multiblock_API.getSpecialBehaviourItemMap()); + } + + // We have a special slot object in the recipe + if (tRecipe.mSpecialItems != null) { + // The special slot is an item + if (tRecipe.mSpecialItems instanceof ItemStack) { + // Make an Itemstack instance of this. + ItemStack aSpecialStack = (ItemStack) tRecipe.mSpecialItems; + // Check if this item is in an input bus. + boolean aDidFindMatch = false; + for (ItemStack aInputItemsToCheck : aItemInputs) { + // If we find a matching stack, continue. + if (GT_Utility.areStacksEqual(aSpecialStack, aInputItemsToCheck, false)) { + // Iterate all special behaviour items, to see if we need to utilise one. + aDidFindMatch = true; + break; + } + } + // Try prevent needless iteration loops if we don't have the required inputs at all. + if (aDidFindMatch) { + // Iterate all special behaviour items, to see if we need to utilise one. + for (SpecialMultiBehaviour aBehaviours : mCustomBehviours.values()) { + // Found a match, let's adjust this recipe now. + if (aBehaviours.isTriggerItem(aSpecialStack)) { + // Adjust this recipe to suit special item + aMaxParallelRecipes = aBehaviours.getMaxParallelRecipes(); + aEUPercent = aBehaviours.getEUPercent(); + aSpeedBonusPercent = aBehaviours.getSpeedBonusPercent(); + aOutputChanceRoll = aBehaviours.getOutputChanceRoll(); + break; + } + } + } + } + } if (!this.canBufferOutputs(tRecipe, aMaxParallelRecipes)) { log("BAD RETURN - 2"); |