use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class SearchUpgradeHandler method checkInventoryForItems.
/**
* This method will be called by the BlockTrackUpgradeHandler when it finds inventories while scanning blocks.
* @param te TileEntity that already has been checked on if it implements IInventory, so it's save to cast it to IInventory.
*/
public void checkInventoryForItems(TileEntity te) {
try {
ItemStack searchStack = ItemPneumaticArmor.getSearchedStack(FMLClientHandler.instance().getClient().thePlayer.getCurrentArmor(3));
IInventory inventory = (IInventory) te;
boolean hasFoundItem = false;
if (searchStack != null) {
for (int l = 0; l < inventory.getSizeInventory(); l++) {
if (inventory.getStackInSlot(l) != null) {
int items = RenderSearchItemBlock.getSearchedItemCount(inventory.getStackInSlot(l), searchStack);
if (items > 0) {
hasFoundItem = true;
searchedItemCounter += items;
}
}
}
}
if (hasFoundItem) {
boolean inList = false;
for (RenderSearchItemBlock trackedBlock : searchedBlocks) {
if (trackedBlock.isAlreadyTrackingCoord(te.xCoord, te.yCoord, te.zCoord)) {
inList = true;
break;
}
}
if (!inList)
searchedBlocks.add(new RenderSearchItemBlock(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord));
}
} catch (Throwable e) {
}
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class BlockTrackEntryInventory method addInformation.
@Override
public void addInformation(World world, int x, int y, int z, TileEntity te, List<String> infoList) {
try {
IInventory inventory = IOHelper.getInventoryForTE(te);
if (inventory != null) {
boolean empty = true;
ItemStack[] inventoryStacks = new ItemStack[inventory.getSizeInventory()];
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack iStack = inventory.getStackInSlot(i);
if (iStack != null)
empty = false;
inventoryStacks[i] = iStack;
}
if (empty) {
infoList.add("Contents: Empty");
} else {
infoList.add("Contents:");
PneumaticCraftUtils.sortCombineItemStacksAndToString(infoList, inventoryStacks);
}
}
} catch (Throwable e) {
addTileEntityToBlackList(te, e);
}
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class LogisticsManager method getRequestedAmount.
public static int getRequestedAmount(SemiBlockLogistics requester, ItemStack providingStack) {
TileEntity te = requester.getTileEntity();
if (!(te instanceof IInventory))
return 0;
int requestedAmount = requester instanceof ISpecificRequester ? ((ISpecificRequester) requester).amountRequested(providingStack) : providingStack.stackSize;
if (requestedAmount == 0)
return 0;
providingStack = providingStack.copy();
providingStack.stackSize = requestedAmount;
ItemStack remainder = providingStack.copy();
remainder.stackSize += requester.getIncomingItems(providingStack);
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
remainder = IOHelper.insert(te, remainder, d, true);
if (remainder == null)
break;
}
if (remainder != null)
providingStack.stackSize -= remainder.stackSize;
if (providingStack.stackSize <= 0)
return 0;
return providingStack.stackSize;
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class LogisticsManager method tryProvide.
//curAI = new DroneAILiquidImport(drone, new FakeWidgetLogistics(provider.getPos(), providingStack));
// transportingFluid = new FluidStackWrapper(providingStack);
private void tryProvide(SemiBlockLogistics provider, SemiBlockLogistics requester, PriorityQueue<LogisticsTask> tasks) {
IInventory providingInventory = IOHelper.getInventoryForTE(provider.getTileEntity());
if (providingInventory != null) {
if (requester instanceof IProvidingInventoryListener)
((IProvidingInventoryListener) requester).notify(provider.getTileEntity());
for (int i = 0; i < providingInventory.getSizeInventory(); i++) {
ItemStack providingStack = providingInventory.getStackInSlot(i);
if (providingStack != null && (!(provider instanceof ISpecificProvider) || ((ISpecificProvider) provider).canProvide(providingStack)) && IOHelper.canExtractItemFromInventory(providingInventory, providingStack, i, 0)) {
int requestedAmount = getRequestedAmount(requester, providingStack);
if (requestedAmount > 0) {
ItemStack stack = providingStack.copy();
stack.stackSize = requestedAmount;
tasks.add(new LogisticsTask(provider, requester, stack));
}
}
}
}
if (provider.getTileEntity() instanceof IFluidHandler) {
IFluidHandler providingTank = (IFluidHandler) provider.getTileEntity();
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
FluidStack providingStack = providingTank.drain(d, 16000, false);
if (providingStack != null && (!(provider instanceof ISpecificProvider) || ((ISpecificProvider) provider).canProvide(providingStack)) && providingTank.canDrain(d, providingStack.getFluid())) {
int requestedAmount = getRequestedAmount(requester, providingStack);
if (requestedAmount > 0) {
FluidStack stack = providingStack.copy();
stack.amount = requestedAmount;
tasks.add(new LogisticsTask(provider, requester, new FluidStackWrapper(stack)));
}
}
}
}
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class BlockPneumaticCraft method dropInventory.
protected void dropInventory(World world, int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory))
return;
IInventory inventory = (IInventory) tileEntity;
Random rand = new Random();
for (int i = getInventoryDropStartSlot(inventory); i < getInventoryDropEndSlot(inventory); i++) {
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0) {
float dX = rand.nextFloat() * 0.8F + 0.1F;
float dY = rand.nextFloat() * 0.8F + 0.1F;
float dZ = rand.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));
if (itemStack.hasTagCompound()) {
entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
}
float factor = 0.05F;
entityItem.motionX = rand.nextGaussian() * factor;
entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
entityItem.motionZ = rand.nextGaussian() * factor;
world.spawnEntityInWorld(entityItem);
itemStack.stackSize = 0;
}
}
}
Aggregations