use of net.minecraft.world.level.block.Mirror in project BYG by AOCAWOL.
the class BYGAbstractTreeFeature method place.
public boolean place(WorldGenLevel worldIn, ChunkGenerator generator, Random rand, BlockPos pos, TFC config) {
if (worldIn.getLevel().dimension() == Level.OVERWORLD && !BYG.ENABLE_OVERWORLD_TREES) {
return false;
}
Rotation rotation = Rotation.values()[rand.nextInt(Rotation.values().length)];
Mirror mirror = Mirror.values()[rand.nextInt(Mirror.values().length)];
config.setRotationAndMirror(rotation, mirror);
return placeTree(worldIn, rand, pos, config);
}
use of net.minecraft.world.level.block.Mirror in project BYG by AOCAWOL.
the class BYGAbstractTreeFeature method getTransformedPos.
public static BlockPos getTransformedPos(BYGTreeConfig config, BlockPos startPos, BlockPos pos) {
Rotation rotation = config.getRotation();
Mirror mirror = config.getMirror();
BlockPos blockPos = FeatureGenUtil.extractOffset(startPos, pos);
if (blockPos instanceof MutableBlockPos) {
FeatureGenUtil.transformMutable((MutableBlockPos) blockPos, mirror, rotation);
((MutableBlockPos) blockPos).move(startPos.getX(), 0, startPos.getZ());
return blockPos;
}
return FeatureGenUtil.transform(blockPos, mirror, rotation).offset(startPos.getX(), 0, startPos.getZ());
}
use of net.minecraft.world.level.block.Mirror in project BCLib by paulevsGitch.
the class NBTStructureFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random random = context.random();
BlockPos center = context.origin();
center = new BlockPos(((center.getX() >> 4) << 4) | 8, 128, ((center.getZ() >> 4) << 4) | 8);
center = getGround(world, center);
if (!canSpawn(world, center, random)) {
return false;
}
int posY = center.getY() + 1;
StructureTemplate structure = getStructure(world, center, random);
Rotation rotation = getRotation(world, center, random);
Mirror mirror = getMirror(world, center, random);
BlockPos offset = StructureTemplate.transform(new BlockPos(structure.getSize()), mirror, rotation, BlockPos.ZERO);
center = center.offset(0, getYOffset(structure, world, center, random) + 0.5, 0);
BoundingBox bounds = makeBox(center);
StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds);
addStructureData(placementData);
center = center.offset(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5);
structure.placeInWorld(world, center, center, placementData, random, 4);
TerrainMerge merge = getTerrainMerge(world, center, random);
int x1 = center.getX();
int z1 = center.getZ();
int x2 = x1 + offset.getX();
int z2 = z1 + offset.getZ();
if (merge != TerrainMerge.NONE) {
MutableBlockPos mut = new MutableBlockPos();
if (x2 < x1) {
int a = x1;
x1 = x2;
x2 = a;
}
if (z2 < z1) {
int a = z1;
z1 = z2;
z2 = a;
}
int surfMax = posY - 1;
for (int x = x1; x <= x2; x++) {
mut.setX(x);
for (int z = z1; z <= z2; z++) {
mut.setZ(z);
mut.setY(surfMax);
BlockState state = world.getBlockState(mut);
if (!isTerrain(state) && state.isFaceSturdy(world, mut, Direction.DOWN)) {
for (int i = 0; i < 10; i++) {
mut.setY(mut.getY() - 1);
BlockState stateSt = world.getBlockState(mut);
if (!isTerrain(stateSt)) {
if (merge == TerrainMerge.SURFACE) {
boolean isTop = mut.getY() == surfMax && state.getMaterial().isSolidBlocking();
Biome b = world.getBiome(mut);
BlockState top = (isTop ? BiomeAPI.findTopMaterial(b) : BiomeAPI.findUnderMaterial(b)).orElse(defaultBlock);
BlocksHelper.setWithoutUpdate(world, mut, top);
} else {
BlocksHelper.setWithoutUpdate(world, mut, state);
}
} else {
if (isTerrain(state) && state.getMaterial().isSolidBlocking()) {
if (merge == TerrainMerge.SURFACE) {
Biome b = world.getBiome(mut);
BlockState bottom = BiomeAPI.findUnderMaterial(b).orElse(defaultBlock);
BlocksHelper.setWithoutUpdate(world, mut, bottom);
} else {
BlocksHelper.setWithoutUpdate(world, mut, state);
}
}
break;
}
}
}
}
}
}
return true;
}
use of net.minecraft.world.level.block.Mirror in project BuildingGadgets by Direwolf20-MC.
the class Template method mirror.
public Template mirror(Axis axis) {
int xFac = 1;
int zFac = 1;
Mirror mirror;
switch(axis) {
case X:
mirror = Mirror.LEFT_RIGHT;
zFac = -1;
break;
case Z:
mirror = Mirror.FRONT_BACK;
xFac = -1;
break;
default:
mirror = Mirror.NONE;
}
Region.Builder regionBuilder = Region.enclosingBuilder();
ImmutableMap.Builder<BlockPos, BlockData> mapBuilder = ImmutableMap.builder();
for (Map.Entry<BlockPos, BlockData> entry : map.entrySet()) {
BlockPos newPos = new BlockPos(entry.getKey().getX() * xFac, entry.getKey().getY(), entry.getKey().getZ() * zFac);
mapBuilder.put(newPos, entry.getValue().mirror(mirror));
regionBuilder.enclose(newPos);
}
return new Template(mapBuilder.build(), TemplateHeader.builderOf(header, regionBuilder.build()).build()).normalize();
}
Aggregations