Search in sources :

Example 1 with TileEntityGravityExtractor

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;
}
Also used : TileEntityGravityExtractor(stevekung.mods.moreplanets.moons.koentus.tileentity.TileEntityGravityExtractor) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Rotation(net.minecraft.util.Rotation) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template) TileEntity(net.minecraft.tileentity.TileEntity) Random(java.util.Random) TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 Random (java.util.Random)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Rotation (net.minecraft.util.Rotation)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 StructureBoundingBox (net.minecraft.world.gen.structure.StructureBoundingBox)1 PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)1 Template (net.minecraft.world.gen.structure.template.Template)1 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)1 TileEntityGravityExtractor (stevekung.mods.moreplanets.moons.koentus.tileentity.TileEntityGravityExtractor)1