use of net.minecraft.tileentity.TileEntityChest in project minecolonies by Minecolonies.
the class TileEntityWareHouse method dumpInventoryIntoWareHouse.
/**
* Dump the inventory of a citizen into the warehouse.
* Go through all items and search the right chest to dump it in.
* @param inventoryCitizen the inventory of the citizen
*/
public void dumpInventoryIntoWareHouse(@NotNull final InventoryCitizen inventoryCitizen) {
for (int i = 0; i < new InvWrapper(inventoryCitizen).getSlots(); i++) {
final ItemStack stack = inventoryCitizen.getStackInSlot(i);
if (InventoryUtils.isItemStackEmpty(stack)) {
continue;
}
@Nullable final TileEntityChest chest = searchRightChestForStack(stack);
if (chest == null) {
LanguageHandler.sendPlayersMessage(getColony().getMessageEntityPlayers(), COM_MINECOLONIES_COREMOD_WAREHOUSE_FULL);
return;
}
InventoryUtils.transferItemStackIntoNextFreeSlotInProvider(new InvWrapper(inventoryCitizen), i, chest);
}
}
use of net.minecraft.tileentity.TileEntityChest in project ArsMagica2 by Mithion.
the class FlickerOperatorItemTransport method FindOutput.
/**
* Will try to find a place to move the item stack
*
* @param stack The item stack to move
* @return Returns true if the item can be moved, returns false otherwise
*/
private boolean FindOutput(World worldObj, TileEntityFlickerHabitat attuner, ItemStack stack, IInventory source) {
HashMap<Integer, ArrayList<AMVector3>> removeFromOutList = new HashMap<Integer, ArrayList<AMVector3>>();
boolean itemMoved = false;
for (int priority = 0; priority <= TileEntityFlickerHabitat.PRIORITY_FINAL; ++priority) {
if (attuner.getOutListPosition(priority) >= attuner.getOutListSize(priority)) {
//if the out list position has gone outside the list size reset it to 0
attuner.setOutListPosition(priority, 0);
}
int start = attuner.getOutListPosition(priority);
int pos = start;
boolean fullLoop = false;
while (!fullLoop) {
//get the crystal marker tile entity for the specified position
AMVector3 vector = attuner.getOutListAt(priority, pos);
TileEntity te = null;
TileEntityCrystalMarker crystalMarkerTE = GetCrystalMarkerTileEntity(worldObj, (int) vector.x, (int) vector.y, (int) vector.z);
if (crystalMarkerTE == null) {
//crystal marker no longer exists, remove it from the list
if (!removeFromOutList.containsKey(priority))
removeFromOutList.put(priority, new ArrayList<AMVector3>());
removeFromOutList.get(priority).add(vector);
break;
}
te = GetAttachedCrystalMarkerTileEntity(worldObj, crystalMarkerTE, vector);
int markerType = worldObj.getBlockMetadata((int) vector.x, (int) vector.y, (int) vector.z);
if (te != null && te instanceof IInventory) {
IInventory inventory = (IInventory) te;
itemMoved = outputItem(markerType, new IInventory[] { inventory }, stack, crystalMarkerTE, new IInventory[] { source });
if (itemMoved) {
attuner.setOutListPosition(priority, pos + 1);
}
}
if (!itemMoved && te instanceof TileEntityChest) {
//This handles the special case of double chests
TileEntityChest adjacent = InventoryUtilities.getAdjacentChest((TileEntityChest) te);
if (adjacent != null) {
IInventory inventory = adjacent;
itemMoved = outputItem(markerType, new IInventory[] { inventory, (IInventory) te }, stack, crystalMarkerTE, new IInventory[] { source });
if (itemMoved) {
attuner.setOutListPosition(priority, pos + 1);
}
}
}
if (itemMoved)
break;
pos++;
pos %= attuner.getOutListSize(priority);
if (pos == start)
fullLoop = true;
}
for (int i : removeFromOutList.keySet()) {
for (AMVector3 vector : removeFromOutList.get(i)) {
attuner.removeOutListAt(i, vector);
}
}
if (!itemMoved) {
attuner.setOutListPosition(priority, 0);
} else {
break;
}
}
return itemMoved;
}
use of net.minecraft.tileentity.TileEntityChest in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method isInHut.
/**
* Check all chests in the worker hut for a required item.
*
* @param is the type of item requested (amount is ignored)
* @return true if a stack of that type was found
*/
public boolean isInHut(@Nullable final ItemStack is) {
@Nullable final AbstractBuildingWorker building = getOwnBuilding();
boolean hasItem;
if (building != null) {
hasItem = isInTileEntity(building.getTileEntity(), is);
if (hasItem) {
return true;
}
for (final BlockPos pos : building.getAdditionalCountainers()) {
final TileEntity entity = world.getTileEntity(pos);
if (entity instanceof TileEntityChest) {
hasItem = isInTileEntity((TileEntityChest) entity, is);
if (hasItem) {
return true;
}
}
}
}
return false;
}
use of net.minecraft.tileentity.TileEntityChest in project minecolonies by Minecolonies.
the class AbstractBuilding method transferStack.
/**
* Try to transfer a stack to one of the inventories of the building.
*
* @param stack the stack to transfer.
* @param world the world to do it in.
* @return The {@link ItemStack} as that is left over, might be {@link InventoryUtils#EMPTY} if the stack was completely accepted
*/
public ItemStack transferStack(@NotNull final ItemStack stack, @NotNull final World world) {
if (tileEntity == null || InventoryUtils.isProviderFull(tileEntity)) {
final Iterator<BlockPos> posIterator = containerList.iterator();
@NotNull ItemStack resultStack = stack.copy();
while (posIterator.hasNext() && !InventoryUtils.isItemStackEmpty(resultStack)) {
final BlockPos pos = posIterator.next();
final TileEntity tempTileEntity = world.getTileEntity(pos);
if (tempTileEntity instanceof TileEntityChest && !InventoryUtils.isProviderFull(tempTileEntity)) {
resultStack = InventoryUtils.addItemStackToProviderWithResult(tempTileEntity, stack);
}
}
return resultStack;
} else {
return InventoryUtils.addItemStackToProviderWithResult(tileEntity, stack);
}
}
Aggregations