Skip to content

Commit

Permalink
What should be a fix to Watchtower building
Browse files Browse the repository at this point in the history
  • Loading branch information
Andromander committed Nov 4, 2020
1 parent 981a852 commit 4a6e661
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Rotation, BlockPos> offsetBig = ImmutableMap.of(
Rotation.NONE, offsetNoneBig,
Rotation.CLOCKWISE_90, offsetC90Big,
Rotation.CLOCKWISE_180, offsetC180Big,
Rotation.COUNTERCLOCKWISE_90, offsetCC90Big
);

private static final ImmutableMap<Rotation, BlockPos> offsetSmall = ImmutableMap.of(
Rotation.NONE, offsetNoneSmall,
Rotation.CLOCKWISE_90, offsetC90Small,
Rotation.CLOCKWISE_180, offsetC180Small,
Rotation.COUNTERCLOCKWISE_90, offsetCC90Small
);

protected static final ImmutableMap<ResourceLocation, BlockPos> centerList = ImmutableMap.<ResourceLocation, BlockPos>builder()
.put(foyer, baseCenter)
Expand All @@ -67,35 +85,27 @@ public class MalachiteWatchtowerPieces {
.put(roof, roofCenter)
.put(roof_m, roofCenter)
.build();
private static final ImmutableMap<ResourceLocation, BlockPos> piecePos = ImmutableMap.<ResourceLocation, BlockPos>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<StructurePiece> 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));
}
}
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 4a6e661

Please sign in to comment.