Search in sources :

Example 16 with TileEntityChest

use of net.minecraft.tileentity.TileEntityChest in project MinecraftForge by MinecraftForge.

the class VanillaDoubleChestItemHandler method get.

@Nullable
public static VanillaDoubleChestItemHandler get(TileEntityChest chest) {
    World world = chest.getWorld();
    BlockPos pos = chest.getPos();
    if (world == null || pos == null || !world.isBlockLoaded(pos))
        // Still loading
        return null;
    Block blockType = chest.getBlockType();
    EnumFacing[] horizontals = EnumFacing.HORIZONTALS;
    for (// Use reverse order so we can return early
    int i = horizontals.length - 1; // Use reverse order so we can return early
    i >= 0; // Use reverse order so we can return early
    i--) {
        EnumFacing enumfacing = horizontals[i];
        BlockPos blockpos = pos.offset(enumfacing);
        Block block = world.getBlockState(blockpos).getBlock();
        if (block == blockType) {
            TileEntity otherTE = world.getTileEntity(blockpos);
            if (otherTE instanceof TileEntityChest) {
                TileEntityChest otherChest = (TileEntityChest) otherTE;
                return new VanillaDoubleChestItemHandler(chest, otherChest, enumfacing != net.minecraft.util.EnumFacing.WEST && enumfacing != net.minecraft.util.EnumFacing.NORTH);
            }
        }
    }
    //All alone
    return NO_ADJACENT_CHESTS_INSTANCE;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Nullable(javax.annotation.Nullable)

Example 17 with TileEntityChest

use of net.minecraft.tileentity.TileEntityChest in project MinecraftForge by MinecraftForge.

the class VanillaDoubleChestItemHandler method equals.

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;
    VanillaDoubleChestItemHandler that = (VanillaDoubleChestItemHandler) o;
    if (hashCode != that.hashCode)
        return false;
    final TileEntityChest otherChest = getOtherChest();
    if (mainChestIsUpper == that.mainChestIsUpper)
        return Objects.equal(mainChest, that.mainChest) && Objects.equal(otherChest, that.getOtherChest());
    else
        return Objects.equal(mainChest, that.getOtherChest()) && Objects.equal(otherChest, that.mainChest);
}
Also used : TileEntityChest(net.minecraft.tileentity.TileEntityChest)

Example 18 with TileEntityChest

use of net.minecraft.tileentity.TileEntityChest in project MinecraftForge by MinecraftForge.

the class VanillaDoubleChestItemHandler method extractItem.

@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate) {
    boolean accessingUpperChest = slot < 27;
    int targetSlot = accessingUpperChest ? slot : slot - 27;
    TileEntityChest chest = getChest(accessingUpperChest);
    return chest != null ? chest.getSingleChestHandler().extractItem(targetSlot, amount, simulate) : ItemStack.EMPTY;
}
Also used : TileEntityChest(net.minecraft.tileentity.TileEntityChest) Nonnull(javax.annotation.Nonnull)

Example 19 with TileEntityChest

use of net.minecraft.tileentity.TileEntityChest in project LogisticsPipes by RS485.

the class InventoryHelper method getInventory.

//BC getInventory with fixed doublechest halves ordering.
public static IInventory getInventory(IInventory inv) {
    if (inv instanceof TileEntityChest) {
        TileEntityChest chest = (TileEntityChest) inv;
        TileEntityChest lower = null;
        TileEntityChest upper = null;
        if (chest.adjacentChestXNeg != null) {
            upper = chest.adjacentChestXNeg;
            lower = chest;
        }
        if (chest.adjacentChestXPos != null) {
            upper = chest;
            lower = chest.adjacentChestXPos;
        }
        if (chest.adjacentChestZNeg != null) {
            upper = chest.adjacentChestZNeg;
            lower = chest;
        }
        if (chest.adjacentChestZPos != null) {
            upper = chest;
            lower = chest.adjacentChestZPos;
        }
        if (lower != null && upper != null) {
            return new InventoryLargeChestLogistics("", upper, lower);
        }
        return inv;
    }
    return inv;
}
Also used : TileEntityChest(net.minecraft.tileentity.TileEntityChest)

Example 20 with TileEntityChest

use of net.minecraft.tileentity.TileEntityChest in project NetherEx by LogicTechCorp.

the class WorldGenUtil method generateStructure.

public static void generateStructure(World world, BlockPos pos, Random rand, Template template, PlacementSettings placementSettings, ResourceLocation[] lootTables, ResourceLocation[] spawnerMobs) {
    try {
        List<Template.BlockInfo> blocks = (List<Template.BlockInfo>) FIELD_BLOCKS.get(template);
        List<Template.EntityInfo> entities = (List<Template.EntityInfo>) FIELD_ENTITIES.get(template);
        if ((!blocks.isEmpty() || !placementSettings.getIgnoreEntities() && !entities.isEmpty()) && template.getSize().getX() >= 1 && template.getSize().getY() >= 1 && template.getSize().getZ() >= 1) {
            BlockRotationProcessor processor = new BlockRotationProcessor(pos, placementSettings);
            Block block = placementSettings.getReplacedBlock();
            StructureBoundingBox boundingBox = placementSettings.getBoundingBox();
            for (Template.BlockInfo blockInfo : blocks) {
                BlockPos blockPos = Template.transformedBlockPos(placementSettings, blockInfo.pos).add(pos);
                Template.BlockInfo blockInfo1 = processor != null ? processor.processBlock(world, blockPos, blockInfo) : blockInfo;
                if (blockInfo1 != null) {
                    Block block1 = blockInfo1.blockState.getBlock();
                    if ((block == null || block != block1) && (!placementSettings.getIgnoreStructureBlock() || block1 != Blocks.STRUCTURE_BLOCK) && (boundingBox == null || boundingBox.isVecInside(blockPos))) {
                        IBlockState state = blockInfo1.blockState.withMirror(placementSettings.getMirror()).withRotation(placementSettings.getRotation());
                        if (blockInfo1.tileentityData != null) {
                            TileEntity tileEntity = world.getTileEntity(blockPos);
                            if (tileEntity != null) {
                                if (tileEntity instanceof IInventory) {
                                    ((IInventory) tileEntity).clear();
                                }
                                world.setBlockState(blockPos, Blocks.BARRIER.getDefaultState(), 4);
                            }
                        }
                        if (world.setBlockState(blockPos, state, 3) && blockInfo1.tileentityData != null) {
                            TileEntity tileEntity = world.getTileEntity(blockPos);
                            if (tileEntity != null) {
                                blockInfo1.tileentityData.setInteger("x", blockPos.getX());
                                blockInfo1.tileentityData.setInteger("y", blockPos.getY());
                                blockInfo1.tileentityData.setInteger("z", blockPos.getZ());
                                tileEntity.readFromNBT(blockInfo1.tileentityData);
                                tileEntity.mirror(placementSettings.getMirror());
                                tileEntity.rotate(placementSettings.getRotation());
                                if (state.getBlock() instanceof BlockChest) {
                                    ((TileEntityChest) tileEntity).setLootTable(lootTables[rand.nextInt(lootTables.length)], rand.nextLong());
                                } else if (state.getBlock() instanceof BlockMobSpawner) {
                                    ((TileEntityMobSpawner) tileEntity).getSpawnerBaseLogic().setEntityId(spawnerMobs[rand.nextInt(spawnerMobs.length)]);
                                } else if (state.getBlock() instanceof BlockUrnOfSorrow) {
                                    ((TileEntityUrnOfSorrow) tileEntity).setCanBreak(false);
                                }
                            }
                        }
                    }
                }
            }
            for (Template.BlockInfo blockInfo2 : blocks) {
                if (block == null || block != blockInfo2.blockState.getBlock()) {
                    BlockPos blockPos1 = Template.transformedBlockPos(placementSettings, blockInfo2.pos).add(pos);
                    if (boundingBox == null || boundingBox.isVecInside(blockPos1)) {
                        world.notifyNeighborsRespectDebug(blockPos1, blockInfo2.blockState.getBlock(), false);
                        if (blockInfo2.tileentityData != null) {
                            TileEntity tileEntity = world.getTileEntity(blockPos1);
                            if (tileEntity != null) {
                                tileEntity.markDirty();
                            }
                        }
                    }
                }
            }
            if (!placementSettings.getIgnoreEntities()) {
                addEntitiesToWorld(world, pos, placementSettings, entities, boundingBox);
            }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) TileEntityChest(net.minecraft.tileentity.TileEntityChest) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) IBlockState(net.minecraft.block.state.IBlockState) BlockChest(net.minecraft.block.BlockChest) BlockUrnOfSorrow(nex.block.BlockUrnOfSorrow) BlockRotationProcessor(net.minecraft.world.gen.structure.template.BlockRotationProcessor) Template(net.minecraft.world.gen.structure.template.Template) TileEntity(net.minecraft.tileentity.TileEntity) BlockMobSpawner(net.minecraft.block.BlockMobSpawner) TileEntityUrnOfSorrow(nex.tileentity.TileEntityUrnOfSorrow) Block(net.minecraft.block.Block) NBTTagList(net.minecraft.nbt.NBTTagList) EntityList(net.minecraft.entity.EntityList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner)

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