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?)
}
}
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);
}
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;
}
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);
}
}
}
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;
}
Aggregations