use of nex.block.BlockUrnOfSorrow 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();
}
}
Aggregations