use of net.minecraft.tileentity.TileEntityChest in project RFToolsDimensions by McJty.
the class GenericWorldGenerator method createLootChest.
private void createLootChest(Random random, World world, BlockPos pos) {
world.setBlockState(pos, Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, EnumFacing.SOUTH));
TileEntity tileentity = world.getTileEntity(pos);
if (tileentity instanceof TileEntityChest) {
switch(random.nextInt(30)) {
case 0:
((TileEntityChest) tileentity).setLootTable(LootTableList.CHESTS_DESERT_PYRAMID, random.nextLong());
break;
case 1:
((TileEntityChest) tileentity).setLootTable(LootTableList.CHESTS_JUNGLE_TEMPLE, random.nextLong());
break;
case 2:
((TileEntityChest) tileentity).setLootTable(LootTableList.CHESTS_VILLAGE_BLACKSMITH, random.nextLong());
break;
case 3:
((TileEntityChest) tileentity).setLootTable(LootTableList.CHESTS_ABANDONED_MINESHAFT, random.nextLong());
break;
case 4:
((TileEntityChest) tileentity).setLootTable(LootTableList.CHESTS_NETHER_BRIDGE, random.nextLong());
break;
case 6:
case 7:
case 8:
((TileEntityChest) tileentity).setLootTable(LostCitiesTerrainGenerator.LOOT, random.nextLong());
break;
default:
((TileEntityChest) tileentity).setLootTable(LootTableList.CHESTS_SIMPLE_DUNGEON, random.nextLong());
break;
}
}
}
use of net.minecraft.tileentity.TileEntityChest in project minecolonies by Minecolonies.
the class EntityAIWorkDeliveryman method gatherItems.
/**
* Gather item from chest.
* Gathers only one stack of the item.
*
* @param buildingToDeliver building to deliver to.
*/
private AIState gatherItems(@NotNull final AbstractBuilding buildingToDeliver, @NotNull final BlockPos position) {
final TileEntity tileEntity = world.getTileEntity(position);
if (tileEntity instanceof TileEntityChest) {
if (!(tileEntity instanceof TileEntityColonyBuilding)) {
if (((TileEntityChest) tileEntity).numPlayersUsing == 0) {
this.world.addBlockEvent(tileEntity.getPos(), tileEntity.getBlockType(), 1, 1);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockType(), true);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos().down(), tileEntity.getBlockType(), true);
setDelay(DUMP_AND_GATHER_DELAY);
return GATHER_IN_WAREHOUSE;
}
this.world.addBlockEvent(tileEntity.getPos(), tileEntity.getBlockType(), 1, 0);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockType(), true);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos().down(), tileEntity.getBlockType(), true);
}
if (buildingToDeliver instanceof BuildingHome) {
final int extraFood = worker.getCitizenData().getSaturation() < EntityCitizen.HIGH_SATURATION ? 1 : 0;
//Tries to extract a certain amount of the item of the chest.
if (InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null), itemStack -> !InventoryUtils.isItemStackEmpty(itemStack) && itemStack.getItem() instanceof ItemFood, buildingToDeliver.getBuildingLevel() + extraFood, new InvWrapper(worker.getInventoryCitizen()))) {
worker.setHeldItem(SLOT_HAND);
setDelay(DUMP_AND_GATHER_DELAY);
return DELIVERY;
}
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
itemsToDeliver.clear();
return START_WORKING;
} else if (itemsToDeliver.isEmpty() && !isToolInTileEntity((TileEntityChest) tileEntity, buildingToDeliver.getRequiredTool(), buildingToDeliver.getBuildingLevel())) {
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
itemsToDeliver.clear();
return START_WORKING;
} else if (!itemsToDeliver.isEmpty()) {
final ItemStack stack = itemsToDeliver.get(0);
if (isInTileEntity((TileEntityChest) tileEntity, stack)) {
itemsToDeliver.remove(0);
worker.setHeldItem(SLOT_HAND);
setDelay(DUMP_AND_GATHER_DELAY);
return DELIVERY;
}
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
itemsToDeliver.clear();
return START_WORKING;
}
}
setDelay(DUMP_AND_GATHER_DELAY);
return GATHER_IN_WAREHOUSE;
}
use of net.minecraft.tileentity.TileEntityChest in project ArsMagica2 by Mithion.
the class FlickerOperatorItemTransport method DoOperation.
@Override
public boolean DoOperation(World worldObj, IFlickerController controller, boolean powered, Affinity[] flickers) {
if (worldObj.isRemote) {
return false;
}
//Gets the habitat running this operation
TileEntityFlickerHabitat habitat = null;
if (controller instanceof TileEntityFlickerHabitat) {
habitat = (TileEntityFlickerHabitat) controller;
} else {
//if the habitat couldn't be found, bail
return false;
}
int toMove = 0;
//if(powered){
for (int i = 0; i < 6; i++) {
if (flickers[i] == Affinity.ARCANE) {
toMove += 32;
}
}
//}
//ensure toMove is at least 1
toMove = Math.max(toMove, 1);
//initiate the arrays for any input crystals
ArrayList<ItemStack> itemsToTransfer = new ArrayList<ItemStack>();
ArrayList<AMVector3> removeFromInList = new ArrayList<AMVector3>();
boolean itemFound = false;
//if the in list position has exceeded the size of the list reset it
if (habitat.getInListPosition() >= habitat.getInListSize()) {
habitat.setInListPosition(0);
}
for (int inIterator = habitat.getInListPosition(); inIterator < habitat.getInListSize(); ++inIterator) {
//Gets the tile entity for the attached crystal marker at the specified location
AMVector3 vector = habitat.getInListAt(inIterator);
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
removeFromInList.add(vector);
break;
}
te = GetAttachedCrystalMarkerTileEntity(worldObj, crystalMarkerTE, vector);
if (te != null && te instanceof IInventory) {
//if the crystal is attached to an inventory
itemFound = moveItem(worldObj, (IInventory) te, crystalMarkerTE, habitat, toMove);
if (itemFound) {
//if an item was found the break out of the current loop
habitat.setInListPosition(inIterator + 1);
break;
} else if (te instanceof TileEntityChest) {
//This is to handle the special case of double chests
TileEntityChest adjacent = InventoryUtilities.getAdjacentChest((TileEntityChest) te);
if (adjacent != null) {
itemFound = moveItem(worldObj, adjacent, crystalMarkerTE, habitat, toMove);
if (itemFound) {
habitat.setInListPosition(inIterator + 1);
}
}
}
}
}
if (itemFound == false) {
//if no items were found to move then reset the input list position
habitat.setInListPosition(0);
}
for (AMVector3 vector : removeFromInList) {
//remove the invalid in list positions from the maintained in list
habitat.removeInListAt(vector);
}
return itemFound;
}
use of net.minecraft.tileentity.TileEntityChest in project ArsMagica2 by Mithion.
the class EntityAIChestDeposit method updateTask.
@Override
public void updateTask() {
AMVector3 iLoc = host.getChestLocation();
if (iLoc == null)
return;
TileEntity te = host.worldObj.getTileEntity((int) iLoc.x, (int) iLoc.y, (int) iLoc.z);
if (te == null || !(te instanceof IInventory))
return;
if (new AMVector3(host).distanceSqTo(iLoc) > 256) {
host.setPosition(iLoc.x, iLoc.y, iLoc.z);
return;
}
if (new AMVector3(host).distanceSqTo(iLoc) > 9) {
host.getNavigator().tryMoveToXYZ(iLoc.x + 0.5, iLoc.y, iLoc.z + 0.5, 0.5f);
} else {
IInventory inventory = (IInventory) te;
if (!isDepositing)
inventory.openInventory();
isDepositing = true;
depositCounter++;
if (depositCounter > 10) {
ItemStack mergeStack = InventoryUtilities.getFirstStackInInventory(host.getBroomInventory()).copy();
int originalSize = mergeStack.stackSize;
if (!InventoryUtilities.mergeIntoInventory(inventory, mergeStack, 1)) {
if (te instanceof TileEntityChest) {
TileEntityChest chest = (TileEntityChest) te;
TileEntityChest adjacent = null;
if (chest.adjacentChestXNeg != null)
adjacent = chest.adjacentChestXNeg;
else if (chest.adjacentChestXPos != null)
adjacent = chest.adjacentChestXPos;
else if (chest.adjacentChestZPos != null)
adjacent = chest.adjacentChestZPos;
else if (chest.adjacentChestZNeg != null)
adjacent = chest.adjacentChestZNeg;
if (adjacent != null) {
InventoryUtilities.mergeIntoInventory(adjacent, mergeStack, 1);
}
}
}
InventoryUtilities.deductFromInventory(host.getBroomInventory(), mergeStack, originalSize - mergeStack.stackSize);
}
if (depositCounter > 10 && (InventoryUtilities.isInventoryEmpty(host.getBroomInventory()) || !InventoryUtilities.canMergeHappen(host.getBroomInventory(), inventory))) {
inventory.closeInventory();
resetTask();
}
}
}
use of net.minecraft.tileentity.TileEntityChest in project minecolonies by Minecolonies.
the class BuildingBuilder method updateAvailableResources.
/**
* Update the available resources.
* <p>
* which are needed for the build and in the builder's chest or inventory
*/
private void updateAvailableResources() {
final EntityCitizen builder = getWorkerEntity();
InventoryCitizen builderInventory = null;
if (builder != null) {
builderInventory = builder.getInventoryCitizen();
}
for (@NotNull final Map.Entry<String, BuildingBuilderResource> entry : neededResources.entrySet()) {
final BuildingBuilderResource resource = entry.getValue();
resource.setAvailable(0);
if (builderInventory != null) {
resource.addAvailable(InventoryUtils.getItemCountInItemHandler(new InvWrapper(builderInventory), resource.getItem(), resource.getDamageValue()));
}
final TileEntity chestInventory = this.getTileEntity();
if (chestInventory != null) {
resource.addAvailable(InventoryUtils.getItemCountInProvider(chestInventory, resource.getItem(), resource.getDamageValue()));
}
//Count in the additional chests as well
if (builder != null) {
for (final BlockPos pos : getAdditionalCountainers()) {
final TileEntity entity = builder.world.getTileEntity(pos);
if (entity instanceof TileEntityChest) {
resource.addAvailable(InventoryUtils.getItemCountInProvider(entity, resource.getItem(), resource.getDamageValue()));
}
}
}
}
}
Aggregations