use of stevekung.mods.moreplanets.moons.koentus.tileentity.TileEntityGravityExtractor in project MorePlanets by SteveKunG.
the class WorldGenGravityHarvester method generate.
@Override
public boolean generate(World world, Random rand, BlockPos pos) {
Random random = world.getChunk(pos).getRandomWithSeed(987234911L);
MinecraftServer server = world.getMinecraftServer();
Rotation[] arotation = CachedEnum.rotationValues;
Rotation rotation = arotation[random.nextInt(arotation.length)];
int i = random.nextInt(GRAVITY_HARVESTERS.length);
TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
Template template = manager.getTemplate(server, GRAVITY_HARVESTERS[i]);
ChunkPos chunkpos = new ChunkPos(pos);
StructureBoundingBox box = new StructureBoundingBox(chunkpos.getXStart(), 0, chunkpos.getZStart(), chunkpos.getXEnd(), 256, chunkpos.getZEnd());
PlacementSettings settings = new PlacementSettings().setRotation(rotation).setBoundingBox(box).setRandom(random);
BlockPos blockpos = template.transformedSize(rotation);
int x = random.nextInt(16 - blockpos.getX());
int z = random.nextInt(16 - blockpos.getZ());
BlockPos blockpos1 = template.getZeroPositionWithTransform(pos.add(x, 0, z), Mirror.NONE, rotation);
Map<BlockPos, String> dataList = template.getDataBlocks(blockpos1, settings);
for (Map.Entry<BlockPos, String> entry : dataList.entrySet()) {
if ("extractor".equals(entry.getValue())) {
BlockPos pos2 = entry.getKey();
world.setBlockState(pos2, MPBlocks.GRAVITY_CREEP_EXTRACTOR.getDefaultState(), 3);
TileEntity tile = world.getTileEntity(pos2);
if (tile instanceof TileEntityGravityExtractor) {
((TileEntityGravityExtractor) tile).setLifeTime(6000 + rand.nextInt(6000));
}
} else if ("extractor_with_vines".equals(entry.getValue())) {
BlockPos pos2 = entry.getKey();
world.setBlockState(pos2, MPBlocks.GRAVITY_CREEP_EXTRACTOR.getDefaultState(), 3);
world.setBlockState(pos2.down(), MPBlocks.GRAVITY_CREEP_VINES.getDefaultState(), 3);
TileEntity tile = world.getTileEntity(pos2);
if (tile instanceof TileEntityGravityExtractor) {
((TileEntityGravityExtractor) tile).setLifeTime(6000 + rand.nextInt(6000));
}
}
}
template.addBlocksToWorld(world, blockpos1, settings, 20);
return true;
}
Aggregations