Search in sources :

Example 6 with TileEntityChest

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;
        }
    }
}
Also used : ModularStorageTileEntity(mcjty.rftools.blocks.storage.ModularStorageTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest)

Example 7 with TileEntityChest

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ItemFood(net.minecraft.item.ItemFood) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) ItemStack(net.minecraft.item.ItemStack)

Example 8 with TileEntityChest

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) TileEntityChest(net.minecraft.tileentity.TileEntityChest) TileEntityCrystalMarker(am2.blocks.tileentities.TileEntityCrystalMarker) TileEntityFlickerHabitat(am2.blocks.tileentities.TileEntityFlickerHabitat) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 9 with TileEntityChest

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();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ItemStack(net.minecraft.item.ItemStack)

Example 10 with TileEntityChest

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()));
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) BuildingBuilderResource(com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource) NotNull(org.jetbrains.annotations.NotNull) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TileEntityChest (net.minecraft.tileentity.TileEntityChest)24 TileEntity (net.minecraft.tileentity.TileEntity)15 BlockPos (net.minecraft.util.math.BlockPos)9 ItemStack (net.minecraft.item.ItemStack)7 Nullable (org.jetbrains.annotations.Nullable)5 IInventory (net.minecraft.inventory.IInventory)4 AMVector3 (am2.api.math.AMVector3)3 HashMap (java.util.HashMap)3 Nonnull (javax.annotation.Nonnull)3 Block (net.minecraft.block.Block)3 NotNull (org.jetbrains.annotations.NotNull)3 TileEntityCrystalMarker (am2.blocks.tileentities.TileEntityCrystalMarker)2 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)2 TileEntityFlickerHabitat (am2.blocks.tileentities.TileEntityFlickerHabitat)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1