diff options
Diffstat (limited to 'src/Java/gtPlusPlus/api/objects/minecraft')
4 files changed, 238 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java b/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java index 25968f1908..04ce0dff19 100644 --- a/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/BTF_Inventory.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import gregtech.api.util.GT_Utility; import gtPlusPlus.core.tileentities.base.TileEntityBase; +import gtPlusPlus.core.util.data.ArrayUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; @@ -19,6 +20,7 @@ public class BTF_Inventory implements ISidedInventory{ } public ItemStack[] getRealInventory() { + purgeNulls(); return this.mInventory; } @@ -139,6 +141,7 @@ public class BTF_Inventory implements ISidedInventory{ public void markDirty() { if (mTile != null) { + purgeNulls(); mTile.markDirty(); } } @@ -160,5 +163,66 @@ public class BTF_Inventory implements ISidedInventory{ return this.mTile != null ? mTile.getInventoryName() : ""; } + public boolean isFull() { + for (int s=0;s<this.getSizeInventory();s++) { + ItemStack slot = mInventory[s]; + if (slot == null || slot.stackSize != slot.getMaxStackSize()) { + return false; + } + } + return true; + } + + public boolean isEmpty() { + for (int s=0;s<this.getSizeInventory();s++) { + ItemStack slot = mInventory[s]; + if (slot == null) { + continue; + } + else { + return false; + } + } + return true; + } + + public boolean addItemStack(ItemStack aInput) { + if (aInput != null & (isEmpty() || !isFull())) { + for (int s = 0; s < this.getSizeInventory(); s++) { + if (mInventory != null && mInventory[s] != null) { + ItemStack slot = mInventory[s]; + if (slot == null || (slot != null && GT_Utility.areStacksEqual(aInput, slot) && slot.stackSize != slot.getItem().getItemStackLimit(slot))) { + if (slot == null) { + slot = aInput.copy(); + } else { + slot.stackSize++; + } + this.setInventorySlotContents(s, slot); + return true; + } + } + } + } + return false; + } + + public final void purgeNulls() { + ItemStack[] aTemp = ArrayUtils.removeNulls(this.mInventory); + for (int g=0;g<this.getSizeInventory();g++) { + if (aTemp.length < this.getSizeInventory()) { + if (g <= aTemp.length-1) { + this.mInventory[g] = aTemp[g]; + } + else { + this.mInventory[g] = null; + } + } + else { + this.mInventory[g] = aTemp[g]; + } + } + + } + } diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java b/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java index 8c940baba3..9ab0f2eefb 100644 --- a/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java +++ b/src/Java/gtPlusPlus/api/objects/minecraft/BlockPos.java @@ -6,6 +6,7 @@ import java.util.Set; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import gtPlusPlus.api.objects.data.AutoMap; @@ -48,6 +49,10 @@ public class BlockPos implements Serializable{ public BlockPos(IGregTechTileEntity b) { this (b.getXCoord(), b.getYCoord(), b.getZCoord(), b.getWorld()); } + + public BlockPos(TileEntity b) { + this (b.xCoord, b.yCoord, b.zCoord, b.getWorldObj()); + } public String getLocationString() { return "[X: "+this.xPos+"][Y: "+this.yPos+"][Z: "+this.zPos+"][Dim: "+this.dim+"]"; diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/ItemPackage.java b/src/Java/gtPlusPlus/api/objects/minecraft/ItemPackage.java new file mode 100644 index 0000000000..fa85f23cf3 --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/minecraft/ItemPackage.java @@ -0,0 +1,58 @@ +package gtPlusPlus.api.objects.minecraft; + +import cpw.mods.fml.common.event.FMLLoadCompleteEvent; +import gtPlusPlus.api.interfaces.RunnableWithInfo; +import gtPlusPlus.core.handler.COMPAT_HANDLER; + +public abstract class ItemPackage implements RunnableWithInfo<String> { + + public ItemPackage() { + this(false); + } + + public ItemPackage(boolean hasExtraLateRun) { + // Register for late run + COMPAT_HANDLER.mObjectsToRunInPostInit.put(this); + if (hasExtraLateRun) { + COMPAT_HANDLER.mObjectsToRunInOnLoadComplete.put(this); + } + init(); + } + + @Override + public final void run() { + generateRecipes(); + } + + @Override + public final String getInfoData() { + return errorMessage(); + } + + public abstract String errorMessage(); + + public abstract boolean generateRecipes(); + + private final void init() { + items(); + blocks(); + fluids(); + } + + public abstract void items(); + + public abstract void blocks(); + + public abstract void fluids(); + + /** + * Override this to handle GT Recipe map manipulation after they're Baked. + * @param event - the {@link FMLLoadCompleteEvent}. + * @return - Did we do anything? + */ + public boolean onLoadComplete(FMLLoadCompleteEvent event) { + return false; + }; + + +} diff --git a/src/Java/gtPlusPlus/api/objects/minecraft/ThreadPooCollector.java b/src/Java/gtPlusPlus/api/objects/minecraft/ThreadPooCollector.java new file mode 100644 index 0000000000..a5f466b19f --- /dev/null +++ b/src/Java/gtPlusPlus/api/objects/minecraft/ThreadPooCollector.java @@ -0,0 +1,111 @@ +package gtPlusPlus.api.objects.minecraft; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; + +import gtPlusPlus.GTplusplus; +import gtPlusPlus.GTplusplus.INIT_PHASE; +import gtPlusPlus.api.objects.data.Pair; +import gtPlusPlus.core.tileentities.machines.TileEntityPooCollector; +import gtPlusPlus.core.util.Utils; +import net.minecraft.entity.passive.EntityAnimal; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +public class ThreadPooCollector extends Thread { + + public boolean canRun = true; + public boolean isRunning = false; + + private static final long INIT_TIME; + private static long internalTickCounter = 0; + + private static final ThreadPooCollector mThread; + private static final HashMap<String, Pair<BlockPos, TileEntityPooCollector>> mPooCollectors = new LinkedHashMap<String, Pair<BlockPos, TileEntityPooCollector>>(); + + + static { + mThread = new ThreadPooCollector(); + INIT_TIME = (System.currentTimeMillis()); + } + + public ThreadPooCollector() { + setName("gtpp.handler.poop"); + run(); + } + + public static ThreadPooCollector getInstance() { + return mThread; + } + + public static void addTask(TileEntityPooCollector aTile) { + BlockPos aTempPos = new BlockPos(aTile); + mPooCollectors.put(aTempPos.getUniqueIdentifier(), new Pair<BlockPos, TileEntityPooCollector>(aTempPos, aTile)); + } + + public static void stopThread() { + mThread.canRun = false; + } + + + @Override + public void run() { + + if (!isRunning) { + isRunning = true; + } + else { + return; + } + + while (canRun) { + if (mPooCollectors.isEmpty() || GTplusplus.CURRENT_LOAD_PHASE != INIT_PHASE.STARTED) { + continue; + } else { + internalTickCounter = Utils.getTicksFromSeconds( + Utils.getSecondsFromMillis(Utils.getMillisSince(INIT_TIME, System.currentTimeMillis()))); + if (internalTickCounter % 100 == 0) { + for (Pair<BlockPos, TileEntityPooCollector> pair : mPooCollectors.values()) { + if (pair != null) { + BlockPos p = pair.getKey(); + if (p != null) { + if (p.world != null) { + World w = p.world; + if (w == null) { + continue; + } + Chunk c = w.getChunkFromBlockCoords(p.xPos, p.zPos); + if (c != null) { + if (c.isChunkLoaded) { + int startX = p.xPos - 2; + int startY = p.yPos; + int startZ = p.zPos - 2; + int endX = p.xPos + 3; + int endY = p.yPos + 5; + int endZ = p.zPos + 3; + AxisAlignedBB box = AxisAlignedBB.getBoundingBox(startX, startY, startZ, + endX, endY, endZ); + if (box != null) { + @SuppressWarnings("unchecked") + List<EntityAnimal> animals = w.getEntitiesWithinAABB(EntityAnimal.class, box); + if (animals != null && !animals.isEmpty()) { + pair.getValue().onPostTick(animals); + } + } else { + continue; + } + } + } + } + } + } + } + } + } + } + } + + +} |