use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class TileEntityAirCannon method updateTrackedItems.
private void updateTrackedItems() {
if (trackedItemIds != null) {
trackedItems.clear();
for (Entity entity : (List<Entity>) worldObj.loadedEntityList) {
if (trackedItemIds.contains(entity.getUniqueID()) && entity instanceof EntityItem) {
trackedItems.add((EntityItem) entity);
}
}
trackedItemIds = null;
}
Iterator<EntityItem> iterator = trackedItems.iterator();
while (iterator.hasNext()) {
EntityItem item = iterator.next();
if (item.worldObj != worldObj || item.isDead) {
iterator.remove();
} else {
Map<ChunkPosition, ForgeDirection> positions = new HashMap<ChunkPosition, ForgeDirection>();
double range = 0.2;
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
double posX = item.posX + d.offsetX * range;
double posY = item.posY + d.offsetY * range;
double posZ = item.posZ + d.offsetZ * range;
positions.put(new ChunkPosition((int) Math.floor(posX), (int) Math.floor(posY), (int) Math.floor(posZ)), d.getOpposite());
}
for (Entry<ChunkPosition, ForgeDirection> entry : positions.entrySet()) {
ChunkPosition pos = entry.getKey();
TileEntity te = worldObj.getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
IInventory inv = IOHelper.getInventoryForTE(te);
ItemStack remainder = IOHelper.insert(inv, item.getEntityItem(), entry.getValue().ordinal(), false);
if (remainder != null) {
item.setEntityItemStack(remainder);
} else {
item.setDead();
iterator.remove();
lastInsertingInventory = new ChunkPosition(te.xCoord, te.yCoord, te.zCoord);
lastInsertingInventorySide = entry.getValue();
break;
}
}
}
}
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class TileEntityAirCannon method inventoryCanCarry.
private boolean inventoryCanCarry() {
insertingInventoryHasSpace = true;
if (lastInsertingInventory == null)
return true;
if (inventory[0] == null)
return true;
TileEntity te = worldObj.getTileEntity(lastInsertingInventory.chunkPosX, lastInsertingInventory.chunkPosY, lastInsertingInventory.chunkPosZ);
IInventory inv = IOHelper.getInventoryForTE(te);
if (inv != null) {
ItemStack remainder = IOHelper.insert(inv, inventory[0].copy(), lastInsertingInventorySide.ordinal(), true);
insertingInventoryHasSpace = remainder == null;
return insertingInventoryHasSpace;
} else {
lastInsertingInventory = null;
lastInsertingInventorySide = null;
return true;
}
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class TileEntityBase method getUpgrades.
protected int getUpgrades(int upgradeDamage, int... upgradeSlots) {
int upgrades = 0;
IInventory inv = null;
if (this instanceof IInventory)
inv = (IInventory) this;
if (inv == null && this instanceof TileEntityPneumaticBase && ((TileEntityPneumaticBase) this).parentTile instanceof IInventory)
inv = (IInventory) ((TileEntityPneumaticBase) this).parentTile;
if (inv != null) {
for (int i : upgradeSlots) {
if (inv.getStackInSlot(i) != null && inv.getStackInSlot(i).getItem() == Itemss.machineUpgrade && inv.getStackInSlot(i).getItemDamage() == upgradeDamage) {
upgrades += inv.getStackInSlot(i).stackSize;
}
}
}
return upgrades;
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class TileEntityBase method processFluidItem.
protected void processFluidItem(int inputSlot, int outputSlot) {
IInventory inv = (IInventory) this;
IFluidHandler fluidHandler = (IFluidHandler) this;
FluidTankInfo tankInfo = fluidHandler.getTankInfo(ForgeDirection.UNKNOWN)[0];
if (inv.getStackInSlot(inputSlot) != null) {
ItemStack fluidContainer = inv.getStackInSlot(inputSlot);
if (tankInfo.fluid == null || tankInfo.fluid.isFluidEqual(fluidContainer)) {
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(fluidContainer);
int amount = FluidContainerRegistry.BUCKET_VOLUME;
if (fluid == null) {
if (fluidContainer.getItem() instanceof IFluidContainerItem) {
IFluidContainerItem containerItem = (IFluidContainerItem) fluidContainer.getItem();
fluid = containerItem.getFluid(fluidContainer);
if (fluid != null && fluidHandler.canFill(ForgeDirection.UNKNOWN, fluid.getFluid())) {
amount = fluid != null ? fluid.amount : 0;
int availableSpace = tankInfo.capacity - (tankInfo.fluid != null ? tankInfo.fluid.amount : 0);
if (availableSpace >= amount) {
ItemStack singleFuelItem = fluidContainer.copy();
singleFuelItem.stackSize = 1;
FluidStack drainedStack = containerItem.drain(singleFuelItem, availableSpace, true);
if (fluidContainer.stackSize == 1 || inv.getStackInSlot(outputSlot) == null || canStack(singleFuelItem, inv.getStackInSlot(outputSlot))) {
fluidHandler.fill(ForgeDirection.UNKNOWN, drainedStack, true);
if (fluidContainer.stackSize == 1) {
inv.setInventorySlotContents(inputSlot, singleFuelItem);
} else {
inv.getStackInSlot(inputSlot).stackSize--;
if (inv.getStackInSlot(outputSlot) == null) {
inv.setInventorySlotContents(outputSlot, singleFuelItem);
} else {
inv.getStackInSlot(outputSlot).stackSize++;
}
}
}
}
}
}
} else if (fluidHandler.canFill(ForgeDirection.UNKNOWN, fluid.getFluid())) {
if (tankInfo.capacity - (tankInfo.fluid != null ? tankInfo.fluid.amount : 0) >= amount) {
ItemStack returnedItem = null;
FluidContainerData[] allFluidData = FluidContainerRegistry.getRegisteredFluidContainerData();
for (FluidContainerData fluidData : allFluidData) {
if (fluidData.filledContainer.isItemEqual(fluidContainer)) {
returnedItem = fluidData.emptyContainer;
break;
}
}
if (returnedItem == null || inv.getStackInSlot(outputSlot) == null || canStack(returnedItem, inv.getStackInSlot(outputSlot))) {
if (returnedItem != null) {
if (inv.getStackInSlot(outputSlot) == null) {
inv.setInventorySlotContents(outputSlot, returnedItem.copy());
} else {
inv.getStackInSlot(outputSlot).stackSize += returnedItem.stackSize;
}
}
fluidHandler.fill(ForgeDirection.UNKNOWN, new FluidStack(fluid.getFluid(), amount, fluid.tag), true);
inv.getStackInSlot(inputSlot).stackSize--;
if (inv.getStackInSlot(inputSlot).stackSize <= 0)
inv.setInventorySlotContents(inputSlot, null);
}
}
}
}
if (fluidContainer.getItem() instanceof IFluidContainerItem) {
if (((IFluidContainerItem) fluidContainer.getItem()).getFluid(fluidContainer) == null && (inv.getStackInSlot(outputSlot) == null || canStack(fluidContainer, inv.getStackInSlot(outputSlot)))) {
if (inv.getStackInSlot(outputSlot) == null) {
inv.setInventorySlotContents(outputSlot, fluidContainer);
} else {
inv.getStackInSlot(outputSlot).stackSize += fluidContainer.stackSize;
}
inv.setInventorySlotContents(inputSlot, null);
}
}
}
}
use of net.minecraft.inventory.IInventory in project PneumaticCraft by MineMaarten.
the class TileEntityAssemblyIOUnit method putItemToCurrentDirection.
private boolean putItemToCurrentDirection() {
if (isImportUnit()) {
TileEntity tile = getTileEntityForCurrentDirection();
if (tile instanceof TileEntityAssemblyPlatform) {
TileEntityAssemblyPlatform plat = (TileEntityAssemblyPlatform) tile;
if (inventory[0] == null)
return plat.closeClaw();
if (plat.isIdle()) {
plat.setHeldStack(inventory[0]);
inventory[0] = null;
return plat.closeClaw();
}
} else
// platform gone; close claw and search new drop-off-location
repeatDropOffSearch();
} else {
IInventory inv = getInventoryForCurrentDirection();
if (// inventory gone; close claw and search new drop-off-location
inv == null)
// inventory gone; close claw and search new drop-off-location
repeatDropOffSearch();
else {
int startSize = inventory[0].stackSize;
for (int i = 0; i < 6; i++) {
inventory[0] = PneumaticCraftUtils.exportStackToInventory(inv, inventory[0], ForgeDirection.getOrientation(i));
if (inventory[0] == null)
break;
}
// TODO - is this still needed? Shouldn't @DescSynced on inventory take care of this?
if (inventory[0] == null || startSize != inventory[0].stackSize)
sendDescriptionPacket();
// target-inventory full or unavailable
if (inventory[0] != null && startSize == inventory[0].stackSize)
repeatDropOffSearch();
}
return inventory[0] == null;
}
return false;
}
Aggregations