Search in sources :

Example 11 with ChestTileEntity

use of net.minecraft.tileentity.ChestTileEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class RoomDecorChest method build.

@Override
public void build(World world, BlockStateGenArray genArray, CastleRoomBase room, DungeonRandomizedCastle dungeon, BlockPos start, Direction side, Set<BlockPos> decoMap) {
    // super.build(world, genArray, room, dungeon, start, side, decoMap);
    ResourceLocation[] chestIDs = room.getChestIDs();
    if (chestIDs != null && chestIDs.length > 0) {
        Block chestBlock = Blocks.CHEST;
        BlockState state = this.schematic.get(0).getState(side);
        ChestTileEntity chest = (ChestTileEntity) chestBlock.createTileEntity(world, state);
        if (chest != null) {
            ResourceLocation resLoc = chestIDs[genArray.getRandom().nextInt(chestIDs.length)];
            if (resLoc != null) {
                long seed = WorldDungeonGenerator.getSeed(world, start.getX() + start.getY(), start.getZ() + start.getY());
                chest.setLootTable(resLoc, seed);
            }
            CompoundNBT nbt = chest.writeToNBT(new CompoundNBT());
            genArray.addBlockState(start, state, nbt, BlockStateGenArray.GenerationPhase.MAIN, BlockStateGenArray.EnumPriority.HIGH);
            decoMap.add(start);
        }
    } else {
    // CQRMain.logger.warn("Placed a chest but could not find a loot table for Room Type {}", room.getRoomType());
    // TODO fix rooms having no chests (or is this intended?)
    }
}
Also used : BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) ChestBlock(net.minecraft.block.ChestBlock) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity)

Example 12 with ChestTileEntity

use of net.minecraft.tileentity.ChestTileEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class GeneratorVegetatedCave method fillChests.

public void fillChests() {
    // DONE: Place and fill chests
    BlockDungeonPart.Builder partBuilder = new BlockDungeonPart.Builder();
    Random random = new Random(WorldDungeonGenerator.getSeed(this.world, this.pos.getX() / 16, this.pos.getZ() / 16));
    ResourceLocation[] chestIDs = this.dungeon.getChestIDs();
    for (BlockPos chestpos : this.chests) {
        Block block = Blocks.CHEST;
        BlockState state = block.defaultBlockState();
        ChestTileEntity chest = (ChestTileEntity) block.createTileEntity(state, this.world);
        if (chest != null) {
            ResourceLocation resLoc = chestIDs[random.nextInt(chestIDs.length)];
            if (resLoc != null) {
                long seed = WorldDungeonGenerator.getSeed(this.world, this.pos.getX() + chestpos.getX() + chestpos.getY(), this.pos.getZ() + chestpos.getZ() + chestpos.getY());
                chest.setLootTable(resLoc, seed);
            }
        }
        CompoundNBT nbt = chest.save(new CompoundNBT());
        partBuilder.add(new PreparableBlockInfo(chestpos.subtract(this.pos), state, nbt));
    }
    this.dungeonBuilder.add(partBuilder);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) BlockDungeonPart(team.cqr.cqrepoured.world.structure.generation.generation.part.BlockDungeonPart) BlockState(net.minecraft.block.BlockState) Random(java.util.Random) ResourceLocation(net.minecraft.util.ResourceLocation) PreparableBlockInfo(team.cqr.cqrepoured.world.structure.generation.generation.preparable.PreparableBlockInfo) HugeMushroomBlock(net.minecraft.block.HugeMushroomBlock) VineBlock(net.minecraft.block.VineBlock) BlockPos(net.minecraft.util.math.BlockPos) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity)

Example 13 with ChestTileEntity

use of net.minecraft.tileentity.ChestTileEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class BlockStateGenArray method addChestWithLootTable.

public boolean addChestWithLootTable(World world, BlockPos pos, Direction facing, ResourceLocation lootTable, GenerationPhase phase) {
    if (lootTable != null) {
        Block chestBlock = Blocks.CHEST;
        BlockState state = Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, facing);
        ChestTileEntity chest = (ChestTileEntity) chestBlock.createTileEntity(state, world);
        if (chest != null) {
            long seed = WorldDungeonGenerator.getSeed(world, pos.getX() + pos.getY(), pos.getZ() + pos.getY());
            chest.setLootTable(lootTable, seed);
            CompoundNBT nbt = chest.save(new CompoundNBT());
            return this.addBlockState(pos, state, nbt, phase, EnumPriority.MEDIUM);
        }
    } else {
        CQRMain.logger.warn("Tried to place a chest with a null loot table");
    }
    return false;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ChestBlock(net.minecraft.block.ChestBlock) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity)

Example 14 with ChestTileEntity

use of net.minecraft.tileentity.ChestTileEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAILooter method tick.

@Override
public void tick() {
    super.tick();
    if (this.entity.getNavigation().createPath(this.currentTarget, 1) == null) {
        this.visitedChests.add(this.currentTarget);
        this.currentTarget = null;
        return;
    }
    if (this.isInLootingRange()) {
        this.entity.getNavigation().stop();
        ChestTileEntity tile = (ChestTileEntity) this.world.getBlockEntity(this.currentTarget);
        // TODO: let it stay open
        if (this.currentLootingTime >= 0) {
            this.currentLootingTime--;
            if (this.currentLootingTime % (this.LOOTING_DURATION / CQRConfig.mobs.looterAIStealableItems) == 0) {
                ItemStack stolenItem = null;
                for (int i = 0; i < tile.getContainerSize(); i++) {
                    if (!tile.getItem(i).isEmpty() && tile.getItem(i).getItem() != Items.BREAD) {
                        stolenItem = tile.removeItemNoUpdate(i);
                        // Suggestion from slayer and i liked it: Leave behind bread
                        ItemStack bread = Items.BREAD.getDefaultInstance();
                        bread.setCount(1);
                        tile.setItem(i, bread);
                        break;
                    }
                }
                if (stolenItem != null) {
                    tile.setChanged();
                    this.entity.swing(Hand.MAIN_HAND);
                    this.entity.swing(Hand.OFF_HAND);
                    ItemStack backpack = this.entity.getItemBySlot(EquipmentSlotType.CHEST);
                    LazyOptional<IItemHandler> lOpCap = backpack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
                    if (lOpCap.isPresent()) {
                        IItemHandler inventory = lOpCap.resolve().get();
                        for (int i = 0; i < inventory.getSlots(); i++) {
                            if (inventory.getStackInSlot(i).isEmpty()) {
                                inventory.insertItem(i, stolenItem, false);
                                break;
                            }
                        }
                    }
                }
            }
        } else {
            this.visitedChests.add(this.currentTarget);
        }
    } else {
        this.entity.getLookControl().setLookAt(this.currentTarget.getX(), this.currentTarget.getY(), this.currentTarget.getZ(), 30, 30);
        if (!this.entity.isPathFinding()) {
            this.entity.getNavigation().moveTo(this.currentTarget.getX(), this.currentTarget.getY(), this.currentTarget.getZ(), 1.125D);
        }
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) ItemStack(net.minecraft.item.ItemStack)

Example 15 with ChestTileEntity

use of net.minecraft.tileentity.ChestTileEntity in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAILooter method canUse.

@Override
public boolean canUse() {
    if (this.cooldown > 0) {
        this.cooldown--;
    }
    if (this.cooldown > 0) {
        return false;
    }
    if (this.entity.tickCount % 4 == 0) {
        if (!this.hasBackpack(this.entity)) {
            return false;
        }
        if (!this.hasBackpackSpace()) {
            return false;
        }
        BlockPos pos = this.entity.blockPosition();
        Vector3d vec = this.entity.getEyePosition(1.0F);
        int horizontalRadius = CQRConfig.mobs.looterAIChestSearchRange;
        int verticalRadius = horizontalRadius >> 1;
        this.currentTarget = BlockPosUtil.getNearest(this.world, pos.getX(), pos.getY() + (MathHelper.ceil(this.entity.getBbHeight()) >> 1), pos.getZ(), horizontalRadius, verticalRadius, true, true, Blocks.CHEST, (mutablePos, state) -> {
            if (this.visitedChests.contains(mutablePos)) {
                return false;
            }
            TileEntity te = this.world.getBlockEntity(mutablePos);
            if (!(te instanceof ChestTileEntity) || ((ChestTileEntity) te).isEmpty()) {
                return false;
            }
            RayTraceResult result = this.world.rayTraceBlocks(vec, new Vector3d(mutablePos.getX() + 0.5D, mutablePos.getY() + 0.5D, mutablePos.getZ() + 0.5D), false, true, false);
            BlockPos.Mutable bp = new BlockPos(result.getLocation()).mutable();
            return result == null || bp.equals(mutablePos);
        });
    }
    return this.currentTarget != null;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) AbstractCQREntityAI(team.cqr.cqrepoured.entity.ai.AbstractCQREntityAI) AbstractEntityCQR(team.cqr.cqrepoured.entity.bases.AbstractEntityCQR) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) BlockPosUtil(team.cqr.cqrepoured.util.BlockPosUtil) Blocks(net.minecraft.block.Blocks) LazyOptional(net.minecraftforge.common.util.LazyOptional) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vector3d(net.minecraft.util.math.vector.Vector3d) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) MathHelper(net.minecraft.util.math.MathHelper) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) TileEntity(net.minecraft.tileentity.TileEntity) Hand(net.minecraft.util.Hand) MobEntity(net.minecraft.entity.MobEntity) ItemBackpack(team.cqr.cqrepoured.item.armor.ItemBackpack) EnumSet(java.util.EnumSet) CQRConfig(team.cqr.cqrepoured.config.CQRConfig) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) ChestTileEntity(net.minecraft.tileentity.ChestTileEntity)

Aggregations

ChestTileEntity (net.minecraft.tileentity.ChestTileEntity)18 TileEntity (net.minecraft.tileentity.TileEntity)13 BlockPos (net.minecraft.util.math.BlockPos)8 TileEntityRack (com.minecolonies.api.tileentities.TileEntityRack)7 World (net.minecraft.world.World)7 ItemStack (net.minecraft.item.ItemStack)6 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 BlockState (net.minecraft.block.BlockState)2 ChestBlock (net.minecraft.block.ChestBlock)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 Set (java.util.Set)1 Block (net.minecraft.block.Block)1 Blocks (net.minecraft.block.Blocks)1 HugeMushroomBlock (net.minecraft.block.HugeMushroomBlock)1 VineBlock (net.minecraft.block.VineBlock)1