diff options
Diffstat (limited to 'src/Java/gtPlusPlus')
4 files changed, 157 insertions, 110 deletions
diff --git a/src/Java/gtPlusPlus/GTplusplus.java b/src/Java/gtPlusPlus/GTplusplus.java index 4d7643e0b0..a6e4589159 100644 --- a/src/Java/gtPlusPlus/GTplusplus.java +++ b/src/Java/gtPlusPlus/GTplusplus.java @@ -44,6 +44,7 @@ import gtPlusPlus.core.util.reflect.ReflectionUtils; import gtPlusPlus.core.util.sys.GeoUtils; import gtPlusPlus.core.util.sys.NetworkUtils; import gtPlusPlus.plugin.manager.Core_Manager; +import gtPlusPlus.xmod.gregtech.api.objects.GregtechBufferThread; import gtPlusPlus.xmod.gregtech.common.Meta_GT_Proxy; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtTools; @@ -173,6 +174,13 @@ public class GTplusplus implements ActionListener { ChunkManager.clearInternalMaps(); } + if (GregtechBufferThread.mBufferThreadAllocation.size() > 0) { + for (GregtechBufferThread i : GregtechBufferThread.mBufferThreadAllocation.values()) { + i.destroy(); + } + GregtechBufferThread.mBufferThreadAllocation.clear(); + } + } @Override @@ -300,7 +308,7 @@ public class GTplusplus implements ActionListener { } String[] machineName = new String[] {"Centrifuge", "Electrolyzer", "Vacuum Freezer"}; for (int i=0;i<3;i++) { - Logger.INFO("[Recipe] Generated "+mValidCount[i]+" recipes for the Industrial "+machineName+". The original machine can process "+mOriginalCount[i]+" recipes, meaning "+mInvalidCount[i]+" are invalid for this Multiblock's processing in some way."); + Logger.INFO("[Recipe] Generated "+mValidCount[i]+" recipes for the Industrial "+machineName[i]+". The original machine can process "+mOriginalCount[i]+" recipes, meaning "+mInvalidCount[i]+" are invalid for this Multiblock's processing in some way."); } } diff --git a/src/Java/gtPlusPlus/xmod/eio/handler/HandlerTooltip_EIO.java b/src/Java/gtPlusPlus/xmod/eio/handler/HandlerTooltip_EIO.java index 788e4d6d9f..d04af8252b 100644 --- a/src/Java/gtPlusPlus/xmod/eio/handler/HandlerTooltip_EIO.java +++ b/src/Java/gtPlusPlus/xmod/eio/handler/HandlerTooltip_EIO.java @@ -17,15 +17,17 @@ import net.minecraftforge.event.entity.player.ItemTooltipEvent; public class HandlerTooltip_EIO { - private static volatile Item mIngot; - private static volatile ItemStack mPulsatingIron; - private static volatile ItemStack mConductiveIron; - private static volatile ItemStack mRedstoneAlloy; - private static volatile ItemStack mElectricalSteel; - private static volatile ItemStack mEnergeticAlloy; - private static volatile ItemStack mVibrantAlloy; - private static volatile ItemStack mSoularium; - private static volatile ItemStack mDarkIron; + private static Item mIngot; + private static ItemStack mPulsatingIron; + private static ItemStack mConductiveIron; + private static ItemStack mRedstoneAlloy; + private static ItemStack mElectricalSteel; + private static ItemStack mEnergeticAlloy; + private static ItemStack mVibrantAlloy; + private static ItemStack mSoularium; + private static ItemStack mDarkIron; + Class oMainClass; + Class oIngotClass; @SubscribeEvent public void onItemTooltip(ItemTooltipEvent event){ @@ -36,8 +38,8 @@ public class HandlerTooltip_EIO { //If it is, reflect in. if (mIngot == null){ try { - Class<?> oMainClass = Class.forName("crazypants.enderio.EnderIO"); - Class<?> oIngotClass = Class.forName("crazypants.enderio.material.ItemAlloy"); + oMainClass = Class.forName("crazypants.enderio.EnderIO"); + oIngotClass = Class.forName("crazypants.enderio.material.ItemAlloy"); if (oMainClass != null && oIngotClass != null){ Field oAlloyField = oMainClass.getDeclaredField("itemAlloy"); @@ -56,77 +58,71 @@ public class HandlerTooltip_EIO { } } - try { - if (mIngot != null){ - //If the Item is an instance of ItemAlloy.class then proceed - if (Class.forName("crazypants.enderio.material.ItemAlloy").isInstance(event.itemStack.getItem()) || event.itemStack.getUnlocalizedName().toLowerCase().contains("item.itemAlloy")){ + if (mIngot != null){ + //If the Item is an instance of ItemAlloy.class then proceed + if (event.itemStack.getItem() == mIngot || oIngotClass.isInstance(event.itemStack.getItem()) || event.itemStack.getUnlocalizedName().toLowerCase().contains("item.itemAlloy")){ - //If EIO Item Is not Null, see if the ItemStacks for the ingots are null - //if they stacks are null, set the stack using the item set via reflection. - //The meta data is based on the oridinals of the materials in the EIO enum. + //If EIO Item Is not Null, see if the ItemStacks for the ingots are null + //if they stacks are null, set the stack using the item set via reflection. + //The meta data is based on the oridinals of the materials in the EIO enum. - if (mElectricalSteel == null){ - mElectricalSteel = ItemUtils.simpleMetaStack(mIngot, 0, 1); - } - if (mEnergeticAlloy == null){ - mEnergeticAlloy = ItemUtils.simpleMetaStack(mIngot, 1, 1); - } - if (mVibrantAlloy == null){ - mVibrantAlloy = ItemUtils.simpleMetaStack(mIngot, 2, 1); - } - if (mRedstoneAlloy == null){ - mRedstoneAlloy = ItemUtils.simpleMetaStack(mIngot, 3, 1); - } - if (mConductiveIron == null){ - mConductiveIron = ItemUtils.simpleMetaStack(mIngot, 4, 1); - } - if (mPulsatingIron == null){ - mPulsatingIron = ItemUtils.simpleMetaStack(mIngot, 5, 1); - } - if (mDarkIron == null){ - mDarkIron = ItemUtils.simpleMetaStack(mIngot, 6, 1); - } - if (mSoularium == null){ - mSoularium = ItemUtils.simpleMetaStack(mIngot, 7, 1); - } + if (mElectricalSteel == null){ + mElectricalSteel = ItemUtils.simpleMetaStack(mIngot, 0, 1); + } + if (mEnergeticAlloy == null){ + mEnergeticAlloy = ItemUtils.simpleMetaStack(mIngot, 1, 1); + } + if (mVibrantAlloy == null){ + mVibrantAlloy = ItemUtils.simpleMetaStack(mIngot, 2, 1); + } + if (mRedstoneAlloy == null){ + mRedstoneAlloy = ItemUtils.simpleMetaStack(mIngot, 3, 1); + } + if (mConductiveIron == null){ + mConductiveIron = ItemUtils.simpleMetaStack(mIngot, 4, 1); + } + if (mPulsatingIron == null){ + mPulsatingIron = ItemUtils.simpleMetaStack(mIngot, 5, 1); + } + if (mDarkIron == null){ + mDarkIron = ItemUtils.simpleMetaStack(mIngot, 6, 1); + } + if (mSoularium == null){ + mSoularium = ItemUtils.simpleMetaStack(mIngot, 7, 1); + } - //If stacks match, add a tooltip. - if (mIngot != null){ - if (event.itemStack.getItem() == mIngot){ - if (event.itemStack.getItemDamage() == 0){ - event.toolTip.add(MaterialEIO.ELECTRICAL_STEEL.vChemicalFormula); - } - else if (event.itemStack.getItemDamage() == 1){ - event.toolTip.add(MaterialEIO.ENERGETIC_ALLOY.vChemicalFormula); - } - else if (event.itemStack.getItemDamage() == 2){ - event.toolTip.add(MaterialEIO.VIBRANT_ALLOY.vChemicalFormula); - } - else if (event.itemStack.getItemDamage() == 3){ - event.toolTip.add(MaterialEIO.REDSTONE_ALLOY.vChemicalFormula); - } - else if (event.itemStack.getItemDamage() == 4){ - event.toolTip.add(MaterialEIO.CONDUCTIVE_IRON.vChemicalFormula); - } - else if (event.itemStack.getItemDamage() == 5){ - event.toolTip.add(MaterialEIO.PULSATING_IRON.vChemicalFormula); - } - else if (event.itemStack.getItemDamage() == 6){ - event.toolTip.add(Materials.DarkSteel.mChemicalFormula); - } - else if (event.itemStack.getItemDamage() == 7){ - event.toolTip.add(MaterialEIO.SOULARIUM.vChemicalFormula); - } + //If stacks match, add a tooltip. + if (mIngot != null){ + if (event.itemStack.getItem() == mIngot){ + if (event.itemStack.getItemDamage() == 0){ + event.toolTip.add(MaterialEIO.ELECTRICAL_STEEL.vChemicalFormula); } - } - } + else if (event.itemStack.getItemDamage() == 1){ + event.toolTip.add(MaterialEIO.ENERGETIC_ALLOY.vChemicalFormula); + } + else if (event.itemStack.getItemDamage() == 2){ + event.toolTip.add(MaterialEIO.VIBRANT_ALLOY.vChemicalFormula); + } + else if (event.itemStack.getItemDamage() == 3){ + event.toolTip.add(MaterialEIO.REDSTONE_ALLOY.vChemicalFormula); + } + else if (event.itemStack.getItemDamage() == 4){ + event.toolTip.add(MaterialEIO.CONDUCTIVE_IRON.vChemicalFormula); + } + else if (event.itemStack.getItemDamage() == 5){ + event.toolTip.add(MaterialEIO.PULSATING_IRON.vChemicalFormula); + } + else if (event.itemStack.getItemDamage() == 6){ + event.toolTip.add(Materials.DarkSteel.mChemicalFormula); + } + else if (event.itemStack.getItemDamage() == 7){ + event.toolTip.add(MaterialEIO.SOULARIUM.vChemicalFormula); + } + } + } } } - catch (ClassNotFoundException e) { - } } - } - } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ThreadedBuffer.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ThreadedBuffer.java index c7914331b7..8dc0a8c2cf 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ThreadedBuffer.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_ThreadedBuffer.java @@ -6,6 +6,7 @@ import net.minecraft.entity.player.EntityPlayer; import gregtech.api.enums.GT_Values; import gregtech.api.util.GT_Utility; +import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.xmod.gregtech.api.objects.GregtechBufferThread; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; @@ -18,6 +19,7 @@ import gregtech.api.interfaces.ITexture; public abstract class GT_MetaTileEntity_ThreadedBuffer extends GT_MetaTileEntity_Buffer { protected GregtechBufferThread mLogicThread; + protected BlockPos mPos; public final ItemStack[] mInventorySynchro; public GT_MetaTileEntity_ThreadedBuffer(final int aID, final String aName, final String aNameRegional, final int aTier, @@ -69,7 +71,7 @@ public abstract class GT_MetaTileEntity_ThreadedBuffer extends GT_MetaTileEntity return mLogicThread; } else { - return this.mLogicThread = GregtechBufferThread.getBufferThread(this.getBaseMetaTileEntity().getWorld()); + return this.mLogicThread = GregtechBufferThread.getBufferThread(mPos); } } @@ -297,8 +299,17 @@ public abstract class GT_MetaTileEntity_ThreadedBuffer extends GT_MetaTileEntity } public synchronized void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTimer) { - if (aBaseMetaTileEntity.isServerSide()) - getLogicThread().onPostTick(aBaseMetaTileEntity, aTimer, this); + if (aBaseMetaTileEntity.isServerSide()) { + if (mPos == null) { + mPos = new BlockPos(this.getBaseMetaTileEntity().getXCoord(), this.getBaseMetaTileEntity().getYCoord(), this.getBaseMetaTileEntity().getZCoord(), this.getBaseMetaTileEntity().getWorld()); + } + if (mLogicThread == null) { + mLogicThread = GregtechBufferThread.getBufferThread(mPos); + } + if (mLogicThread!= null) { + getLogicThread().onPostTick(aBaseMetaTileEntity, aTimer, this); + } + } } public void onFirstTick(final IGregTechTileEntity aBaseMetaTileEntity) { diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechBufferThread.java b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechBufferThread.java index 15f4ad503f..47c53d18f1 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechBufferThread.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/objects/GregtechBufferThread.java @@ -7,51 +7,55 @@ import java.util.Map; import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.world.World; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Utility; import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.api.objects.minecraft.BlockPos; import gtPlusPlus.xmod.gregtech.api.metatileentity.implementations.GT_MetaTileEntity_ThreadedBuffer; import gtPlusPlus.xmod.gregtech.common.tileentities.automation.GT_MetaTileEntity_ThreadedChestBuffer; public class GregtechBufferThread extends Thread { public static final Map<String, GregtechBufferThread> mBufferThreadAllocation = new HashMap<String, GregtechBufferThread>(); - private final World mWorldRef; - private short mLifeCycleTime = 900; + private final BlockPos mBlockPos; + private int mLifeCycleTime = 300; + private final String mID; - public static synchronized final GregtechBufferThread getBufferThread(World world) { - if (world != null && mBufferThreadAllocation.containsKey(""+world.provider.dimensionId)){ + public static synchronized final GregtechBufferThread getBufferThread(BlockPos pos) { + if (pos != null && mBufferThreadAllocation.containsKey(""+pos.getUniqueIdentifier())){ Logger.INFO("[SB] Found an existing thread for this dimension."); - return mBufferThreadAllocation.get(""+world.provider.dimensionId); + return mBufferThreadAllocation.get(""+pos.getUniqueIdentifier()); } else { - return new GregtechBufferThread(world); + return new GregtechBufferThread(pos); } } - public GregtechBufferThread(World world) { + public GregtechBufferThread(BlockPos pos) { super(); - int mID = world != null ? world.provider.dimensionId : Short.MIN_VALUE; - if (world != null && !mBufferThreadAllocation.containsKey(""+mID)){ - mWorldRef = world; - mBufferThreadAllocation.put(""+mID, this); + String aID = pos != null ? pos.getUniqueIdentifier() : ""+Short.MIN_VALUE; + this.mID = aID; + if (pos != null && !mBufferThreadAllocation.containsKey(mID)){ + mBlockPos = pos; + mBufferThreadAllocation.put(mID, this); } else { this.mLifeCycleTime = 1; - mWorldRef = null; + mBlockPos = null; } - this.setName("GTPP_SuperBuffer-Dim("+mID+")"); - if (mWorldRef != null && !this.isAlive()) { - this.start(); + this.setName("GTPP-SuperBuffer("+mID+")"); + if (mBlockPos != null && !this.isAlive()) { + start(); Logger.INFO("[SB] Created a SuperBuffer Thread for dimension "+mID+"."); } } public synchronized void fillStacksIntoFirstSlots(GT_MetaTileEntity_ThreadedChestBuffer mBuffer) { - mLifeCycleTime += 100; + if (mLifeCycleTime < (Short.MAX_VALUE-10)){ + mLifeCycleTime += 10; + } for (int i = 0; i < mBuffer.mInventorySynchro.length - 1; ++i) { for (int j = i + 1; j < mBuffer.mInventorySynchro.length - 1; ++j) { if (mBuffer.mInventorySynchro[j] != null && (mBuffer.mInventorySynchro[i] == null @@ -64,7 +68,9 @@ public class GregtechBufferThread extends Thread { } public synchronized boolean moveItems(final IGregTechTileEntity aBaseMetaTileEntity, final long aTimer, GT_MetaTileEntity_ThreadedBuffer mBuffer) { - mLifeCycleTime += 100; + if (mLifeCycleTime < (Short.MAX_VALUE-10)){ + mLifeCycleTime += 10; + } final byte mTargetStackSize = (byte) mBuffer.mTargetStackSize; final int tCost = GT_Utility.moveOneItemStack((Object) aBaseMetaTileEntity, (Object) aBaseMetaTileEntity.getTileEntityAtSide(aBaseMetaTileEntity.getBackFacing()), @@ -85,6 +91,10 @@ public class GregtechBufferThread extends Thread { && (aBaseMetaTileEntity.hasWorkJustBeenEnabled() || aBaseMetaTileEntity.hasInventoryBeenModified() || aTimer % 200L == 0L || mBuffer.mSuccess > 0)) { --mBuffer.mSuccess; + if (mLifeCycleTime < (Short.MAX_VALUE-1)){ + mLifeCycleTime += 1; + } + //Logger.INFO("Ticking SB @ "+mBuffer.getLogicThread().mBlockPos.getUniqueIdentifier() + " | Time Left: "+mLifeCycleTime); moveItems(aBaseMetaTileEntity, aTimer, mBuffer); for (byte b = 0; b < 6; ++b) { aBaseMetaTileEntity.setInternalOutputRedstoneSignal(b, (byte) (mBuffer.bInvert ? 15 : 0)); @@ -168,23 +178,45 @@ public class GregtechBufferThread extends Thread { return 0; } + //Logic Vars + private boolean mRunning = true; + @Override - public void run() { - while (mLifeCycleTime > 0) { - mLifeCycleTime--; - Logger.INFO("[SB] Ticking Thread for dimension. "+mLifeCycleTime); - try { - this.sleep(1000); + public void run() { + //While thread is alive. + while (mRunning) { + //While thread is active, lets tick it's life down. + while (mLifeCycleTime > 0) { + //Remove invalid threads + if (this.mBlockPos.world == null) { + mLifeCycleTime = 0; + } + //Prevent Overflows + if (mLifeCycleTime > Short.MAX_VALUE) { + mLifeCycleTime = Short.MAX_VALUE; + } + try { + sleep(1000); + mLifeCycleTime--; + Logger.INFO("[SB] Ticking Thread "+mID+" | Remaining: "+mLifeCycleTime+"s"); + } + catch (InterruptedException e) { + mLifeCycleTime = 0; + } } - catch (InterruptedException e) { - + if (mLifeCycleTime <= 0) { + destroy(); } } - if (mLifeCycleTime <= 0) { - int mID = (mWorldRef != null ? mWorldRef.provider.dimensionId : Short.MIN_VALUE); - GregtechBufferThread.mBufferThreadAllocation.remove(""+mID, this); - Logger.INFO("[SB] Removing Thread for dimension "+mID); - } + } + + @Override + public void destroy() { + GregtechBufferThread.mBufferThreadAllocation.remove(mID, this); + Logger.INFO("[SB] Removing Thread "+mID); + mRunning = false; + mLifeCycleTime = 0; + stop(); } |