diff --git a/src/main/java/androsa/gaiadimension/world/gen/structure/MalachiteWatchtowerStructure.java b/src/main/java/androsa/gaiadimension/world/gen/structure/MalachiteWatchtowerStructure.java index 6237cbb51..e63aeac70 100644 --- a/src/main/java/androsa/gaiadimension/world/gen/structure/MalachiteWatchtowerStructure.java +++ b/src/main/java/androsa/gaiadimension/world/gen/structure/MalachiteWatchtowerStructure.java @@ -16,6 +16,7 @@ import net.minecraft.world.biome.BiomeManager; import net.minecraft.world.gen.ChunkGenerator; import net.minecraft.world.gen.GenerationSettings; +import net.minecraft.world.gen.Heightmap; import net.minecraft.world.gen.feature.NoFeatureConfig; import net.minecraft.world.gen.feature.structure.Structure; import net.minecraft.world.gen.feature.structure.StructurePiece; @@ -118,12 +119,33 @@ public Start(Structure structure, int chunkX, int chunkZ, MutableBoundingBox @Override public void init(ChunkGenerator generator, TemplateManager manager, int chunkX, int chunkZ, Biome biome) { - int x = chunkX * 16; - int z = chunkZ * 16; - BlockPos blockpos = new BlockPos(x, 90, z); - Rotation rotation = Rotation.values()[this.rand.nextInt(Rotation.values().length)]; - MalachiteWatchtowerPieces.buildStructure(manager, blockpos, rotation, this.components, this.rand); - this.recalculateStructureSize(); + Rotation rotation = Rotation.randomRotation(this.rand); + int oX = 5; + int oZ = 5; + if (rotation == Rotation.CLOCKWISE_90) { + oX = -5; + } else if (rotation == Rotation.CLOCKWISE_180) { + oX = -5; + oZ = -5; + } else if (rotation == Rotation.COUNTERCLOCKWISE_90) { + oZ = -5; + } + + int cX = (chunkX << 4) + 7; + int cZ = (chunkZ << 4) + 7; + int c1 = generator.func_222531_c(cX, cZ, Heightmap.Type.WORLD_SURFACE_WG); + int c2 = generator.func_222531_c(cX, cZ + oZ, Heightmap.Type.WORLD_SURFACE_WG); + int c3 = generator.func_222531_c(cX + oX, cZ, Heightmap.Type.WORLD_SURFACE_WG); + int c4 = generator.func_222531_c(cX + oX, cZ + oZ, Heightmap.Type.WORLD_SURFACE_WG); + int height = Math.min(Math.min(c1, c2), Math.min(c3, c4)); + + if (height >= 60) { + int x = chunkX * 16; + int z = chunkZ * 16; + BlockPos blockpos = new BlockPos(x + 8, height + 1, z + 8); + MalachiteWatchtowerPieces.buildStructure(manager, blockpos, rotation, this.components, this.rand); + this.recalculateStructureSize(); + } } @Override diff --git a/src/main/java/androsa/gaiadimension/world/gen/structure/pieces/MalachiteWatchtowerPieces.java b/src/main/java/androsa/gaiadimension/world/gen/structure/pieces/MalachiteWatchtowerPieces.java index c96de426c..6e252c6f9 100644 --- a/src/main/java/androsa/gaiadimension/world/gen/structure/pieces/MalachiteWatchtowerPieces.java +++ b/src/main/java/androsa/gaiadimension/world/gen/structure/pieces/MalachiteWatchtowerPieces.java @@ -14,11 +14,8 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.MutableBoundingBox; import net.minecraft.world.IWorld; -import net.minecraft.world.gen.ChunkGenerator; -import net.minecraft.world.gen.Heightmap; import net.minecraft.world.gen.feature.structure.StructurePiece; import net.minecraft.world.gen.feature.structure.TemplateStructurePiece; import net.minecraft.world.gen.feature.template.BlockIgnoreStructureProcessor; @@ -55,9 +52,30 @@ public class MalachiteWatchtowerPieces { private static final BlockPos baseCenter = new BlockPos(15, 15, 15); private static final BlockPos f1Center = new BlockPos(12, 11, 12); private static final BlockPos roofCenter = new BlockPos(16, 23, 16); - private static final BlockPos blockpos_1 = new BlockPos(0, 0, 0); - private static final BlockPos blockpos_2 = new BlockPos(1, 0, 0); - private static final BlockPos blockpos_3 = new BlockPos(-2, 0, -3); + + private static final BlockPos offsetNoneBig = new BlockPos(5, 0, 6); + private static final BlockPos offsetC90Big = new BlockPos(0, 0, 5); + private static final BlockPos offsetC180Big = new BlockPos(1, 0, 0); + private static final BlockPos offsetCC90Big = new BlockPos(6, 0, 1); + + private static final BlockPos offsetNoneSmall = new BlockPos(0, 0, 1); + private static final BlockPos offsetC90Small = new BlockPos(-3, 0, 0); + private static final BlockPos offsetC180Small = new BlockPos(-2, 0, -3); + private static final BlockPos offsetCC90Small = new BlockPos(1, 0, -2); + + private static final ImmutableMap offsetBig = ImmutableMap.of( + Rotation.NONE, offsetNoneBig, + Rotation.CLOCKWISE_90, offsetC90Big, + Rotation.CLOCKWISE_180, offsetC180Big, + Rotation.COUNTERCLOCKWISE_90, offsetCC90Big + ); + + private static final ImmutableMap offsetSmall = ImmutableMap.of( + Rotation.NONE, offsetNoneSmall, + Rotation.CLOCKWISE_90, offsetC90Small, + Rotation.CLOCKWISE_180, offsetC180Small, + Rotation.COUNTERCLOCKWISE_90, offsetCC90Small + ); protected static final ImmutableMap centerList = ImmutableMap.builder() .put(foyer, baseCenter) @@ -67,35 +85,27 @@ public class MalachiteWatchtowerPieces { .put(roof, roofCenter) .put(roof_m, roofCenter) .build(); - private static final ImmutableMap piecePos = ImmutableMap.builder() - .put(foyer, blockpos_1) - .put(floor1_1, blockpos_2).put(floor1_2, blockpos_2).put(floor1_3, blockpos_2) - .put(floor_random1, blockpos_2).put(floor_random2, blockpos_2).put(floor_random3, blockpos_2).put(floor_random4, blockpos_2).put(floor_random5, blockpos_2) - .put(floor_random1_m, blockpos_2).put(floor_random2_m, blockpos_2).put(floor_random3_m, blockpos_2).put(floor_random4_m, blockpos_2).put(floor_random5_m, blockpos_2) - .put(roof, blockpos_3) - .put(roof_m, blockpos_3) - .build(); public static void buildStructure(TemplateManager manager, BlockPos pos, Rotation rotation, List pieces, Random random) { int i = 0; pieces.add(new MalachiteWatchtowerPieces.Piece(manager, foyer, pos, rotation, i)); - i += 12; - pieces.add(new MalachiteWatchtowerPieces.Piece(manager, first_floors[random.nextInt(first_floors.length)], pos, rotation, i)); + i += 14; + pieces.add(new MalachiteWatchtowerPieces.Piece(manager, first_floors[random.nextInt(first_floors.length)], pos.add(offsetBig.get(rotation)), rotation, i)); int r = random.nextInt(2) + 4; for (int f = 0; f < r; f++) { i += 10; if (f == r - 1) { if (f % 2 == 0) { - pieces.add(new MalachiteWatchtowerPieces.Piece(manager, roof_m, pos, rotation, i)); + pieces.add(new MalachiteWatchtowerPieces.Piece(manager, roof_m, pos.add(offsetSmall.get(rotation)), rotation, i)); } else { - pieces.add(new MalachiteWatchtowerPieces.Piece(manager, roof, pos, rotation, i)); + pieces.add(new MalachiteWatchtowerPieces.Piece(manager, roof, pos.add(offsetSmall.get(rotation)), rotation, i)); } } else { if (f % 2 == 0) { - pieces.add(new MalachiteWatchtowerPieces.Piece(manager, next_floors[random.nextInt(next_floors.length)], pos, rotation, i)); + pieces.add(new MalachiteWatchtowerPieces.Piece(manager, next_floors[random.nextInt(next_floors.length)], pos.add(offsetBig.get(rotation)), rotation, i)); } else { - pieces.add(new MalachiteWatchtowerPieces.Piece(manager, next_floors_m[random.nextInt(next_floors_m.length)], pos, rotation, i)); + pieces.add(new MalachiteWatchtowerPieces.Piece(manager, next_floors_m[random.nextInt(next_floors_m.length)], pos.add(offsetBig.get(rotation)), rotation, i)); } } } @@ -112,8 +122,7 @@ public static class Piece extends TemplateStructurePiece { public Piece(TemplateManager manager, ResourceLocation pieceloc, BlockPos pos, Rotation rot, int offset) { super(ModWorldgen.MAWA, 0); this.pieceLocation = pieceloc; - BlockPos blockpos = MalachiteWatchtowerPieces.piecePos.get(pieceloc); - this.templatePosition = pos.add(blockpos.getX(), blockpos.getY() + offset, blockpos.getZ()); + this.templatePosition = pos.add(0, offset, 0); this.rotation = rot; this.loadTemplate(manager); } @@ -167,24 +176,5 @@ protected void handleDataMarker(String name, BlockPos pos, IWorld world, Random world.setBlockState(pos, ModBlocks.malachite_guard_spawner.get().getDefaultState(), 3); } } - - @Override - public boolean generate(IWorld world, ChunkGenerator generator, Random random, MutableBoundingBox mbb, ChunkPos chunkpos) { - this.placeSettings - .setRotation(this.rotation) - .setMirror(Mirror.NONE) - .setCenterOffset(MalachiteWatchtowerPieces.centerList.get(this.pieceLocation)) - .addProcessor(BlockIgnoreStructureProcessor.STRUCTURE_BLOCK) - .addProcessor(new MalachiteDegradeProcessor(0.2F)); - - BlockPos blockpos = MalachiteWatchtowerPieces.piecePos.get(this.pieceLocation); - BlockPos blockpos1 = this.templatePosition.add(Template.transformedBlockPos(placeSettings, new BlockPos(3 - blockpos.getX(), 0, 0 - blockpos.getZ()))); - int height = world.getHeight(Heightmap.Type.WORLD_SURFACE_WG, blockpos1.getX(), blockpos1.getZ()); - BlockPos blockpos2 = this.templatePosition; - this.templatePosition = this.templatePosition.add(0, height - 90 - 1, 0); - boolean flag = super.generate(world, generator, random, mbb, chunkpos); - this.templatePosition = blockpos2; - return flag; - } } }