Search in sources :

Example 1 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project NetherEx by LogicTechCorp.

the class WorldGenCeilingStructure method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    rand = world.getChunkFromBlockCoords(pos).getRandomWithSeed(world.getSeed());
    Mirror[] mirrors = Mirror.values();
    Rotation[] rotations = Rotation.values();
    Mirror mirror = mirrors[rand.nextInt(mirrors.length)];
    Rotation rotation = rotations[rand.nextInt(rotations.length)];
    MinecraftServer server = world.getMinecraftServer();
    TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
    Template template = manager.getTemplate(server, WeightedUtil.getRandomStructure(rand, variants));
    PlacementSettings placementSettings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.STRUCTURE_VOID).setRandom(rand);
    BlockPos structureSize = Template.transformedBlockPos(placementSettings, template.getSize());
    BlockPos newPos = new BlockPos(pos.getX() - structureSize.getX() / 2, 48, pos.getZ() - structureSize.getZ() / 2);
    BlockPos spawnPos = WorldGenUtil.getSuitableCeilingPos(world, newPos, structureSize);
    if (!spawnPos.equals(BlockPos.ORIGIN)) {
        WorldGenUtil.generateStructure(world, spawnPos, rand, template, placementSettings, lootTables, spawnerMobs);
        return true;
    }
    return false;
}
Also used : TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Mirror(net.minecraft.util.Mirror) Rotation(net.minecraft.util.Rotation) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template)

Example 2 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project NetherEx by LogicTechCorp.

the class WorldGenWallStructure method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    rand = world.getChunkFromBlockCoords(pos).getRandomWithSeed(world.getSeed());
    Mirror[] mirrors = Mirror.values();
    Rotation[] rotations = Rotation.values();
    Mirror mirror = mirrors[rand.nextInt(mirrors.length)];
    Rotation rotation = rotations[rand.nextInt(rotations.length)];
    MinecraftServer server = world.getMinecraftServer();
    TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
    Template template = manager.getTemplate(server, WeightedUtil.getRandomStructure(rand, variants));
    PlacementSettings placementSettings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.AIR).setRandom(rand);
    BlockPos structureSize = Template.transformedBlockPos(placementSettings, template.getSize());
    BlockPos newPos = new BlockPos(pos.getX() - structureSize.getX() / 2, 96, pos.getZ() - structureSize.getZ() / 2);
    BlockPos spawnPos = WorldGenUtil.getSuitableWallPos(world, newPos, structureSize, 0.8F);
    if (!spawnPos.equals(BlockPos.ORIGIN)) {
        WorldGenUtil.generateStructure(world, spawnPos, rand, template, placementSettings, lootTables, spawnerMobs);
        return true;
    }
    return false;
}
Also used : TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Mirror(net.minecraft.util.Mirror) Rotation(net.minecraft.util.Rotation) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template)

Example 3 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project minecolonies by Minecolonies.

the class StructureProxy method rotateWithMirror.

/**
 * Rotate the structure depending on the direction it's facing.
 *
 * @param times     times to rotateWithMirror.
 * @param world     the world to rotateWithMirror it in.
 * @param rotatePos the pos to rotateWithMirror it around.
 * @param mirror    the mirror
 */
public void rotateWithMirror(final int times, final World world, final BlockPos rotatePos, final Mirror mirror) {
    final Rotation rotation;
    switch(times) {
        case ROTATE_ONCE:
            rotation = Rotation.CLOCKWISE_90;
            break;
        case ROTATE_TWICE:
            rotation = Rotation.CLOCKWISE_180;
            break;
        case ROTATE_THREE_TIMES:
            rotation = Rotation.COUNTERCLOCKWISE_90;
            break;
        default:
            rotation = Rotation.NONE;
    }
    structure.setPlacementSettings(new PlacementSettings().setRotation(rotation).setMirror(mirror));
    final BlockPos size = structure.getSize(rotation);
    this.width = size.getX();
    this.height = size.getY();
    this.length = size.getZ();
    this.blocks = new Template.BlockInfo[width][height][length];
    this.entities = new Template.EntityInfo[width][height][length];
    int minX = 0;
    int minY = 0;
    int minZ = 0;
    for (final Template.BlockInfo info : structure.getBlockInfoWithSettings(new PlacementSettings().setRotation(rotation).setMirror(mirror))) {
        final BlockPos tempPos = info.pos;
        final int x = tempPos.getX();
        final int y = tempPos.getY();
        final int z = tempPos.getZ();
        if (x < minX) {
            minX = x;
        }
        if (y < minY) {
            minY = y;
        }
        if (z < minZ) {
            minZ = z;
        }
    }
    minX = Math.abs(minX);
    minY = Math.abs(minY);
    minZ = Math.abs(minZ);
    boolean foundHut = false;
    final PlacementSettings settings = new PlacementSettings().setRotation(rotation).setMirror(mirror);
    for (final Template.BlockInfo info : structure.getBlockInfoWithSettings(settings)) {
        final BlockPos tempPos = info.pos;
        final int x = tempPos.getX() + minX;
        final int y = tempPos.getY() + minY;
        final int z = tempPos.getZ() + minZ;
        this.blocks[x][y][z] = info;
        this.entities[x][y][z] = null;
        if (info.blockState.getBlock() instanceof AbstractBlockHut) {
            foundHut = true;
            offset = info.pos.add(minX, minY, minZ);
        }
        if (info.tileentityData != null) {
            final TileEntity entity = TileEntity.create(world, info.tileentityData);
            entity.rotate(rotation);
            entity.mirror(mirror);
            this.blocks[x][y][z] = new Template.BlockInfo(info.pos, info.blockState, entity.writeToNBT(new NBTTagCompound()));
        }
    }
    updateOffSetIfDecoration(foundHut, size, times, minX, minY, minZ);
    for (final Template.EntityInfo info : structure.getTileEntities()) {
        final Template.EntityInfo newInfo = structure.transformEntityInfoWithSettings(info, world, rotatePos.subtract(offset).add(new BlockPos(minX, minY, minZ)), settings);
        // 289 74 157 - 289.9 76.5, 157.5
        final BlockPos tempPos = Template.transformedBlockPos(settings, info.blockPos);
        final int x = tempPos.getX() + minX;
        final int y = tempPos.getY() + minY;
        final int z = tempPos.getZ() + minZ;
        this.entities[x][y][z] = newInfo;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Rotation(net.minecraft.util.Rotation) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) Template(net.minecraft.world.gen.structure.template.Template)

Example 4 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project minecolonies by Minecolonies.

the class RenderEventHandler method onRenderWorldLast.

/**
 * Event used to render the schematics. Only render the schematic if there is one in the settings.
 *
 * @param event Object containing event details.
 */
@SubscribeEvent
public void onRenderWorldLast(final RenderWorldLastEvent event) {
    final Structure structure = Settings.instance.getActiveStructure();
    if (structure != null) {
        BlockPos size = structure.getSize(BlockUtils.getRotation(Settings.instance.getRotation()));
        BlockPos position = Settings.instance.getPosition();
        final int x = size.getX();
        final int z = size.getZ();
        final int y = size.getY();
        if (Settings.instance.getRotation() == 1) {
            size = new BlockPos(-x, y, z);
        }
        if (Settings.instance.getRotation() == 2) {
            size = new BlockPos(-x, y, -z);
        }
        if (Settings.instance.getRotation() == 3) {
            size = new BlockPos(x, y, -z);
        }
        final BlockPos offset = Settings.instance.getOffset(new PlacementSettings().setRotation(BlockUtils.getRotation(Settings.instance.getRotation())).setMirror(Settings.instance.getMirror()));
        if (offset.equals(new BlockPos(0, 0, 0))) {
            position = position.subtract(new BlockPos(size.getX() / 2, 0, size.getZ() / 2));
        } else {
            position = position.subtract(offset);
        }
        structure.renderStructure(position, Minecraft.getMinecraft().world, Minecraft.getMinecraft().player, event.getPartialTicks());
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Structure(com.minecolonies.structures.helpers.Structure) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project minecolonies by Minecolonies.

the class WindowBuildTool method changeSchematic.

/*
     * ---------------- Miscellaneous ----------------
     */
/**
 * Changes the current structure.
 * Set to button position at that time
 */
private void changeSchematic() {
    final String sname;
    if (Settings.instance.isStaticSchematicMode()) {
        sname = Settings.instance.getStaticSchematicName();
    } else {
        sname = schematics.get(schematicsDropDownList.getSelectedIndex());
    }
    final StructureName structureName = new StructureName(sname);
    final Structure structure = new Structure(null, structureName.toString(), new PlacementSettings().setRotation(BlockUtils.getRotation(Settings.instance.getRotation())).setMirror(Settings.instance.getMirror()));
    final String md5 = Structures.getMD5(structureName.toString());
    if (structure.isTemplateMissing() || !structure.isCorrectMD5(md5)) {
        if (structure.isTemplateMissing()) {
            Log.getLogger().info("Template structure " + structureName + " missing");
        } else {
            Log.getLogger().info("structure " + structureName + " md5 error");
        }
        Log.getLogger().info("Request To Server for structure " + structureName);
        if (FMLCommonHandler.instance().getMinecraftServerInstance() == null) {
            MineColonies.getNetwork().sendToServer(new SchematicRequestMessage(structureName.toString()));
            return;
        } else {
            Log.getLogger().error("WindowBuildTool: Need to download schematic on a standalone client/server. This should never happen");
        }
    }
    Settings.instance.setStructureName(structureName.toString());
    Settings.instance.setActiveSchematic(structure);
    if (Settings.instance.getPosition() == null) {
        Settings.instance.setPosition(this.pos);
    }
}
Also used : SchematicRequestMessage(com.minecolonies.coremod.network.messages.SchematicRequestMessage) StructureName(com.minecolonies.coremod.colony.StructureName) Structure(com.minecolonies.structures.helpers.Structure) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings)

Aggregations

PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)18 BlockPos (net.minecraft.util.math.BlockPos)16 Template (net.minecraft.world.gen.structure.template.Template)13 Rotation (net.minecraft.util.Rotation)10 MinecraftServer (net.minecraft.server.MinecraftServer)9 IBlockState (net.minecraft.block.state.IBlockState)7 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)7 Mirror (net.minecraft.util.Mirror)6 Map (java.util.Map)4 TileEntity (net.minecraft.tileentity.TileEntity)4 EnumFacing (net.minecraft.util.EnumFacing)4 TileEntityLockableLoot (net.minecraft.tileentity.TileEntityLockableLoot)3 Structure (com.minecolonies.structures.helpers.Structure)2 Vector3 (net.katsstuff.mirror.data.Vector3)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 AreaDescriptor (WayofTime.bloodmagic.ritual.AreaDescriptor)1 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 StructureName (com.minecolonies.coremod.colony.StructureName)1 SchematicRequestMessage (com.minecolonies.coremod.network.messages.SchematicRequestMessage)1 Block (net.minecraft.block.Block)1