public class WorldGenStructure extends WorldGenerator implements IStructure
{
public static String structureName;
public WorldGenStructure (String name)
{
this.structureName = name;
}
@Override
public boolean generate(World worldIn, Random rand, BlockPos position)
{
this.generateStructure(worldIn, position, rand);
return true;
}
public static void generateStructure(World world, BlockPos pos, Random rand)
{
MinecraftServer mcServer = world.getMinecraftServer();
TemplateManager manager = worldServer.getStructureTemplateManager();
ResourceLocation location = new ResourceLocation(Reference.MODID, structureName);
Template template = manager.get(mcServer, location);
if(template != null)
{
IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);
template.addBlocksToWorldChunk(world, pos, settings);
for(int x = 0; x <= template.getSize().getX(); x++) {
for(int y = 0; y <= template.getSize().getY(); y++) {
for(int z = 0; z <= template.getSize().getZ(); z++){
BlockPos tmp = new BlockPos(pos.getX() + x, pos.getY() + y, pos.getZ() + z);
if(world.getTileEntity(tmp) != null){
if(world.getTileEntity(tmp) instanceof TileEntityChest){
TileEntityChest chest = (TileEntityChest) world.getTileEntity(tmp);
((TileEntityChest)chest).setLootTable(new ResourceLocation(Reference.MODID + ":chests/" + structureName), rand.nextLong());
}
}
}
}
}
}
}
}