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;
}
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;
}
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;
}
}
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());
}
}
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);
}
}
Aggregations