| 1 | package net.minecraft.world.level.levelgen.structure.structures;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.core.BlockPos;
|
| 6 | import net.minecraft.nbt.CompoundTag;
|
| 7 | import net.minecraft.resources.Identifier;
|
| 8 | import net.minecraft.resources.ResourceKey;
|
| 9 | import net.minecraft.tags.BlockTags;
|
| 10 | import net.minecraft.tags.FluidTags;
|
| 11 | import net.minecraft.util.Mth;
|
| 12 | import net.minecraft.util.RandomSource;
|
| 13 | import net.minecraft.util.Util;
|
| 14 | import net.minecraft.util.valueproviders.ConstantInt;
|
| 15 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 16 | import net.minecraft.world.entity.EntityTypes;
|
| 17 | import net.minecraft.world.entity.monster.zombie.Drowned;
|
| 18 | import net.minecraft.world.level.BlockGetter;
|
| 19 | import net.minecraft.world.level.ChunkPos;
|
| 20 | import net.minecraft.world.level.ServerLevelAccessor;
|
| 21 | import net.minecraft.world.level.StructureManager;
|
| 22 | import net.minecraft.world.level.WorldGenLevel;
|
| 23 | import net.minecraft.world.level.block.Block;
|
| 24 | import net.minecraft.world.level.block.Blocks;
|
| 25 | import net.minecraft.world.level.block.ChestBlock;
|
| 26 | import net.minecraft.world.level.block.Mirror;
|
| 27 | import net.minecraft.world.level.block.Rotation;
|
| 28 | import net.minecraft.world.level.block.entity.ChestBlockEntity;
|
| 29 | import net.minecraft.world.level.block.state.BlockState;
|
| 30 | import net.minecraft.world.level.chunk.ChunkGenerator;
|
| 31 | import net.minecraft.world.level.levelgen.Heightmap;
|
| 32 | import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
| 33 | import net.minecraft.world.level.levelgen.structure.TemplateStructurePiece;
|
| 34 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
|
| 35 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType;
|
| 36 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePiecesBuilder;
|
| 37 | import net.minecraft.world.level.levelgen.structure.templatesystem.AlwaysTrueTest;
|
| 38 | import net.minecraft.world.level.levelgen.structure.templatesystem.BlockIgnoreProcessor;
|
| 39 | import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest;
|
| 40 | import net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor;
|
| 41 | import net.minecraft.world.level.levelgen.structure.templatesystem.CappedProcessor;
|
| 42 | import net.minecraft.world.level.levelgen.structure.templatesystem.PosAlwaysTrueTest;
|
| 43 | import net.minecraft.world.level.levelgen.structure.templatesystem.ProcessorRule;
|
| 44 | import net.minecraft.world.level.levelgen.structure.templatesystem.RuleProcessor;
|
| 45 | import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
|
| 46 | import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessor;
|
| 47 | import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
|
| 48 | import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
|
| 49 | import net.minecraft.world.level.levelgen.structure.templatesystem.rule.blockentity.AppendLoot;
|
| 50 | import net.minecraft.world.level.material.FluidState;
|
| 51 | import net.minecraft.world.level.storage.loot.BuiltInLootTables;
|
| 52 | import net.minecraft.world.level.storage.loot.LootTable;
|
| 53 |
|
| 54 | public class OceanRuinPieces {
|
| 55 | private static final StructureProcessor WARM_SUSPICIOUS_BLOCK_PROCESSOR = archyRuleProcessor(
|
| 56 | Blocks.SAND, Blocks.SUSPICIOUS_SAND, BuiltInLootTables.OCEAN_RUIN_WARM_ARCHAEOLOGY
|
| 57 | );
|
| 58 | private static final StructureProcessor COLD_SUSPICIOUS_BLOCK_PROCESSOR = archyRuleProcessor(
|
| 59 | Blocks.GRAVEL, Blocks.SUSPICIOUS_GRAVEL, BuiltInLootTables.OCEAN_RUIN_COLD_ARCHAEOLOGY
|
| 60 | );
|
| 61 | private static final Identifier[] WARM_RUINS = new Identifier[]{
|
| 62 | Identifier.withDefaultNamespace("underwater_ruin/warm_1"),
|
| 63 | Identifier.withDefaultNamespace("underwater_ruin/warm_2"),
|
| 64 | Identifier.withDefaultNamespace("underwater_ruin/warm_3"),
|
| 65 | Identifier.withDefaultNamespace("underwater_ruin/warm_4"),
|
| 66 | Identifier.withDefaultNamespace("underwater_ruin/warm_5"),
|
| 67 | Identifier.withDefaultNamespace("underwater_ruin/warm_6"),
|
| 68 | Identifier.withDefaultNamespace("underwater_ruin/warm_7"),
|
| 69 | Identifier.withDefaultNamespace("underwater_ruin/warm_8")
|
| 70 | };
|
| 71 | private static final Identifier[] RUINS_BRICK = new Identifier[]{
|
| 72 | Identifier.withDefaultNamespace("underwater_ruin/brick_1"),
|
| 73 | Identifier.withDefaultNamespace("underwater_ruin/brick_2"),
|
| 74 | Identifier.withDefaultNamespace("underwater_ruin/brick_3"),
|
| 75 | Identifier.withDefaultNamespace("underwater_ruin/brick_4"),
|
| 76 | Identifier.withDefaultNamespace("underwater_ruin/brick_5"),
|
| 77 | Identifier.withDefaultNamespace("underwater_ruin/brick_6"),
|
| 78 | Identifier.withDefaultNamespace("underwater_ruin/brick_7"),
|
| 79 | Identifier.withDefaultNamespace("underwater_ruin/brick_8")
|
| 80 | };
|
| 81 | private static final Identifier[] RUINS_CRACKED = new Identifier[]{
|
| 82 | Identifier.withDefaultNamespace("underwater_ruin/cracked_1"),
|
| 83 | Identifier.withDefaultNamespace("underwater_ruin/cracked_2"),
|
| 84 | Identifier.withDefaultNamespace("underwater_ruin/cracked_3"),
|
| 85 | Identifier.withDefaultNamespace("underwater_ruin/cracked_4"),
|
| 86 | Identifier.withDefaultNamespace("underwater_ruin/cracked_5"),
|
| 87 | Identifier.withDefaultNamespace("underwater_ruin/cracked_6"),
|
| 88 | Identifier.withDefaultNamespace("underwater_ruin/cracked_7"),
|
| 89 | Identifier.withDefaultNamespace("underwater_ruin/cracked_8")
|
| 90 | };
|
| 91 | private static final Identifier[] RUINS_MOSSY = new Identifier[]{
|
| 92 | Identifier.withDefaultNamespace("underwater_ruin/mossy_1"),
|
| 93 | Identifier.withDefaultNamespace("underwater_ruin/mossy_2"),
|
| 94 | Identifier.withDefaultNamespace("underwater_ruin/mossy_3"),
|
| 95 | Identifier.withDefaultNamespace("underwater_ruin/mossy_4"),
|
| 96 | Identifier.withDefaultNamespace("underwater_ruin/mossy_5"),
|
| 97 | Identifier.withDefaultNamespace("underwater_ruin/mossy_6"),
|
| 98 | Identifier.withDefaultNamespace("underwater_ruin/mossy_7"),
|
| 99 | Identifier.withDefaultNamespace("underwater_ruin/mossy_8")
|
| 100 | };
|
| 101 | private static final Identifier[] BIG_RUINS_BRICK = new Identifier[]{
|
| 102 | Identifier.withDefaultNamespace("underwater_ruin/big_brick_1"),
|
| 103 | Identifier.withDefaultNamespace("underwater_ruin/big_brick_2"),
|
| 104 | Identifier.withDefaultNamespace("underwater_ruin/big_brick_3"),
|
| 105 | Identifier.withDefaultNamespace("underwater_ruin/big_brick_8")
|
| 106 | };
|
| 107 | private static final Identifier[] BIG_RUINS_MOSSY = new Identifier[]{
|
| 108 | Identifier.withDefaultNamespace("underwater_ruin/big_mossy_1"),
|
| 109 | Identifier.withDefaultNamespace("underwater_ruin/big_mossy_2"),
|
| 110 | Identifier.withDefaultNamespace("underwater_ruin/big_mossy_3"),
|
| 111 | Identifier.withDefaultNamespace("underwater_ruin/big_mossy_8")
|
| 112 | };
|
| 113 | private static final Identifier[] BIG_RUINS_CRACKED = new Identifier[]{
|
| 114 | Identifier.withDefaultNamespace("underwater_ruin/big_cracked_1"),
|
| 115 | Identifier.withDefaultNamespace("underwater_ruin/big_cracked_2"),
|
| 116 | Identifier.withDefaultNamespace("underwater_ruin/big_cracked_3"),
|
| 117 | Identifier.withDefaultNamespace("underwater_ruin/big_cracked_8")
|
| 118 | };
|
| 119 | private static final Identifier[] BIG_WARM_RUINS = new Identifier[]{
|
| 120 | Identifier.withDefaultNamespace("underwater_ruin/big_warm_4"),
|
| 121 | Identifier.withDefaultNamespace("underwater_ruin/big_warm_5"),
|
| 122 | Identifier.withDefaultNamespace("underwater_ruin/big_warm_6"),
|
| 123 | Identifier.withDefaultNamespace("underwater_ruin/big_warm_7")
|
| 124 | };
|
| 125 |
|
| 126 | private static StructureProcessor archyRuleProcessor(final Block candidateBlock, final Block replacementBlock, final ResourceKey<LootTable> lootTable) {
|
| 127 | return new CappedProcessor(
|
| 128 | new RuleProcessor(
|
| 129 | List.of(
|
| 130 | new ProcessorRule(
|
| 131 | new BlockMatchTest(candidateBlock), AlwaysTrueTest.INSTANCE, PosAlwaysTrueTest.INSTANCE, replacementBlock.defaultBlockState(), new AppendLoot(lootTable)
|
| 132 | )
|
| 133 | )
|
| 134 | ),
|
| 135 | ConstantInt.of(5)
|
| 136 | );
|
| 137 | }
|
| 138 |
|
| 139 | private static Identifier getSmallWarmRuin(final RandomSource random) {
|
| 140 | return Util.getRandom(WARM_RUINS, random);
|
| 141 | }
|
| 142 |
|
| 143 | private static Identifier getBigWarmRuin(final RandomSource random) {
|
| 144 | return Util.getRandom(BIG_WARM_RUINS, random);
|
| 145 | }
|
| 146 |
|
| 147 | public static void addPieces(
|
| 148 | final StructureTemplateManager structureTemplateManager,
|
| 149 | final BlockPos position,
|
| 150 | final Rotation rotation,
|
| 151 | final StructurePiecesBuilder builder,
|
| 152 | final RandomSource random,
|
| 153 | final OceanRuinStructure structure
|
| 154 | ) {
|
| 155 | boolean isLarge = random.nextFloat() <= structure.largeProbability;
|
| 156 | float baseIntegrity = isLarge ? 0.9F : 0.8F;
|
| 157 | addPiece(structureTemplateManager, position, rotation, builder, random, structure, isLarge, baseIntegrity);
|
| 158 | if (isLarge && random.nextFloat() <= structure.clusterProbability) {
|
| 159 | addClusterRuins(structureTemplateManager, random, rotation, position, structure, builder);
|
| 160 | }
|
| 161 | }
|
| 162 |
|
| 163 | private static void addClusterRuins(
|
| 164 | final StructureTemplateManager structureTemplateManager,
|
| 165 | final RandomSource random,
|
| 166 | final Rotation rotation,
|
| 167 | final BlockPos p,
|
| 168 | final OceanRuinStructure structure,
|
| 169 | final StructurePiecesBuilder builder
|
| 170 | ) {
|
| 171 | BlockPos parentPos = new BlockPos(p.getX(), 90, p.getZ());
|
| 172 | BlockPos parentCorner = StructureTemplate.transform(new BlockPos(15, 0, 15), Mirror.NONE, rotation, BlockPos.ZERO).offset(parentPos);
|
| 173 | BoundingBox parentBB = BoundingBox.fromCorners(parentPos, parentCorner);
|
| 174 | BlockPos parentBottomLeft = new BlockPos(Math.min(parentPos.getX(), parentCorner.getX()), parentPos.getY(), Math.min(parentPos.getZ(), parentCorner.getZ()));
|
| 175 | List<BlockPos> allPositions = allPositions(random, parentBottomLeft);
|
| 176 | int ruins = Mth.nextInt(random, 4, 8);
|
| 177 |
|
| 178 | for (int i = 0; i < ruins; i++) {
|
| 179 | if (!allPositions.isEmpty()) {
|
| 180 | int idx = random.nextInt(allPositions.size());
|
| 181 | BlockPos pos = allPositions.remove(idx);
|
| 182 | Rotation nextRotation = Rotation.getRandom(random);
|
| 183 | BlockPos nextCorner = StructureTemplate.transform(new BlockPos(5, 0, 6), Mirror.NONE, nextRotation, BlockPos.ZERO).offset(pos);
|
| 184 | BoundingBox nextBB = BoundingBox.fromCorners(pos, nextCorner);
|
| 185 | if (!nextBB.intersects(parentBB)) {
|
| 186 | addPiece(structureTemplateManager, pos, nextRotation, builder, random, structure, false, 0.8F);
|
| 187 | }
|
| 188 | }
|
| 189 | }
|
| 190 | }
|
| 191 |
|
| 192 | private static List<BlockPos> allPositions(final RandomSource random, final BlockPos origin) {
|
| 193 | List<BlockPos> positions = Lists.newArrayList();
|
| 194 | positions.add(origin.offset(-16 + Mth.nextInt(random, 1, 8), 0, 16 + Mth.nextInt(random, 1, 7)));
|
| 195 | positions.add(origin.offset(-16 + Mth.nextInt(random, 1, 8), 0, Mth.nextInt(random, 1, 7)));
|
| 196 | positions.add(origin.offset(-16 + Mth.nextInt(random, 1, 8), 0, -16 + Mth.nextInt(random, 4, 8)));
|
| 197 | positions.add(origin.offset(Mth.nextInt(random, 1, 7), 0, 16 + Mth.nextInt(random, 1, 7)));
|
| 198 | positions.add(origin.offset(Mth.nextInt(random, 1, 7), 0, -16 + Mth.nextInt(random, 4, 6)));
|
| 199 | positions.add(origin.offset(16 + Mth.nextInt(random, 1, 7), 0, 16 + Mth.nextInt(random, 3, 8)));
|
| 200 | positions.add(origin.offset(16 + Mth.nextInt(random, 1, 7), 0, Mth.nextInt(random, 1, 7)));
|
| 201 | positions.add(origin.offset(16 + Mth.nextInt(random, 1, 7), 0, -16 + Mth.nextInt(random, 4, 8)));
|
| 202 | return positions;
|
| 203 | }
|
| 204 |
|
| 205 | private static void addPiece(
|
| 206 | final StructureTemplateManager structureTemplateManager,
|
| 207 | final BlockPos position,
|
| 208 | final Rotation rotation,
|
| 209 | final StructurePiecesBuilder builder,
|
| 210 | final RandomSource random,
|
| 211 | final OceanRuinStructure structure,
|
| 212 | final boolean isLarge,
|
| 213 | final float baseIntegrity
|
| 214 | ) {
|
| 215 | switch (structure.biomeTemp) {
|
| 216 | case WARM:
|
| 217 | default:
|
| 218 | Identifier startPieceLocation = isLarge ? getBigWarmRuin(random) : getSmallWarmRuin(random);
|
| 219 | builder.addPiece(
|
| 220 | new OceanRuinPieces.OceanRuinPiece(structureTemplateManager, startPieceLocation, position, rotation, baseIntegrity, structure.biomeTemp, isLarge)
|
| 221 | );
|
| 222 | break;
|
| 223 | case COLD:
|
| 224 | Identifier[] bricks = isLarge ? BIG_RUINS_BRICK : RUINS_BRICK;
|
| 225 | Identifier[] cracked = isLarge ? BIG_RUINS_CRACKED : RUINS_CRACKED;
|
| 226 | Identifier[] mossy = isLarge ? BIG_RUINS_MOSSY : RUINS_MOSSY;
|
| 227 | int idx = random.nextInt(bricks.length);
|
| 228 | builder.addPiece(new OceanRuinPieces.OceanRuinPiece(structureTemplateManager, bricks[idx], position, rotation, baseIntegrity, structure.biomeTemp, isLarge));
|
| 229 | builder.addPiece(new OceanRuinPieces.OceanRuinPiece(structureTemplateManager, cracked[idx], position, rotation, 0.7F, structure.biomeTemp, isLarge));
|
| 230 | builder.addPiece(new OceanRuinPieces.OceanRuinPiece(structureTemplateManager, mossy[idx], position, rotation, 0.5F, structure.biomeTemp, isLarge));
|
| 231 | }
|
| 232 | }
|
| 233 |
|
| 234 | public static class OceanRuinPiece extends TemplateStructurePiece {
|
| 235 | private final OceanRuinStructure.Type biomeType;
|
| 236 | private final float integrity;
|
| 237 | private final boolean isLarge;
|
| 238 |
|
| 239 | public OceanRuinPiece(
|
| 240 | final StructureTemplateManager structureTemplateManager,
|
| 241 | final Identifier templateLocation,
|
| 242 | final BlockPos position,
|
| 243 | final Rotation rotation,
|
| 244 | final float integrity,
|
| 245 | final OceanRuinStructure.Type biomeType,
|
| 246 | final boolean isLarge
|
| 247 | ) {
|
| 248 | super(
|
| 249 | StructurePieceType.OCEAN_RUIN,
|
| 250 | 0,
|
| 251 | structureTemplateManager,
|
| 252 | templateLocation,
|
| 253 | templateLocation.toString(),
|
| 254 | makeSettings(rotation, integrity, biomeType),
|
| 255 | position
|
| 256 | );
|
| 257 | this.integrity = integrity;
|
| 258 | this.biomeType = biomeType;
|
| 259 | this.isLarge = isLarge;
|
| 260 | }
|
| 261 |
|
| 262 | private OceanRuinPiece(
|
| 263 | final StructureTemplateManager structureTemplateManager,
|
| 264 | final CompoundTag tag,
|
| 265 | final Rotation rotation,
|
| 266 | final float integrity,
|
| 267 | final OceanRuinStructure.Type biomeType,
|
| 268 | final boolean isLarge
|
| 269 | ) {
|
| 270 | super(StructurePieceType.OCEAN_RUIN, tag, structureTemplateManager, location -> makeSettings(rotation, integrity, biomeType));
|
| 271 | this.integrity = integrity;
|
| 272 | this.biomeType = biomeType;
|
| 273 | this.isLarge = isLarge;
|
| 274 | }
|
| 275 |
|
| 276 | private static StructurePlaceSettings makeSettings(final Rotation rotation, final float integrity, final OceanRuinStructure.Type biomeType) {
|
| 277 | StructureProcessor suspiciousBlockProcessor = biomeType == OceanRuinStructure.Type.COLD
|
| 278 | ? OceanRuinPieces.COLD_SUSPICIOUS_BLOCK_PROCESSOR
|
| 279 | : OceanRuinPieces.WARM_SUSPICIOUS_BLOCK_PROCESSOR;
|
| 280 | return new StructurePlaceSettings()
|
| 281 | .setRotation(rotation)
|
| 282 | .setMirror(Mirror.NONE)
|
| 283 | .addProcessor(new BlockRotProcessor(integrity))
|
| 284 | .addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR)
|
| 285 | .addProcessor(suspiciousBlockProcessor);
|
| 286 | }
|
| 287 |
|
| 288 | public static OceanRuinPieces.OceanRuinPiece create(final StructureTemplateManager structureTemplateManager, final CompoundTag tag) {
|
| 289 | Rotation rotation = tag.read("Rot", Rotation.LEGACY_CODEC).orElseThrow();
|
| 290 | float integrity = tag.getFloatOr("Integrity", 0.0F);
|
| 291 | OceanRuinStructure.Type biomeType = tag.read("BiomeType", OceanRuinStructure.Type.LEGACY_CODEC).orElseThrow();
|
| 292 | boolean isLarge = tag.getBooleanOr("IsLarge", false);
|
| 293 | return new OceanRuinPieces.OceanRuinPiece(structureTemplateManager, tag, rotation, integrity, biomeType, isLarge);
|
| 294 | }
|
| 295 |
|
| 296 | @Override
|
| 297 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 298 | super.addAdditionalSaveData(context, tag);
|
| 299 | tag.store("Rot", Rotation.LEGACY_CODEC, this.placeSettings.getRotation());
|
| 300 | tag.putFloat("Integrity", this.integrity);
|
| 301 | tag.store("BiomeType", OceanRuinStructure.Type.LEGACY_CODEC, this.biomeType);
|
| 302 | tag.putBoolean("IsLarge", this.isLarge);
|
| 303 | }
|
| 304 |
|
| 305 | @Override
|
| 306 | protected void handleDataMarker(
|
| 307 | final String markerId, final BlockPos position, final ServerLevelAccessor level, final RandomSource random, final BoundingBox chunkBB
|
| 308 | ) {
|
| 309 | if ("chest".equals(markerId)) {
|
| 310 | level.setBlock(position, Blocks.CHEST.defaultBlockState().setValue(ChestBlock.WATERLOGGED, level.getFluidState(position).is(FluidTags.WATER)), 2);
|
| 311 | if (level.getBlockEntity(position) instanceof ChestBlockEntity chestBlockEntity) {
|
| 312 | chestBlockEntity.setLootTable(this.isLarge ? BuiltInLootTables.UNDERWATER_RUIN_BIG : BuiltInLootTables.UNDERWATER_RUIN_SMALL, random.nextLong());
|
| 313 | }
|
| 314 | } else if ("drowned".equals(markerId)) {
|
| 315 | Drowned drowned = EntityTypes.DROWNED.create(level.getLevel(), EntitySpawnReason.STRUCTURE);
|
| 316 | if (drowned != null) {
|
| 317 | drowned.setPersistenceRequired();
|
| 318 | drowned.snapTo(position, 0.0F, 0.0F);
|
| 319 | drowned.finalizeSpawn(level, level.getCurrentDifficultyAt(position), EntitySpawnReason.STRUCTURE, null);
|
| 320 | level.addFreshEntityWithPassengers(drowned);
|
| 321 | if (position.getY() > level.getSeaLevel()) {
|
| 322 | level.setBlock(position, Blocks.AIR.defaultBlockState(), 2);
|
| 323 | } else {
|
| 324 | level.setBlock(position, Blocks.WATER.defaultBlockState(), 2);
|
| 325 | }
|
| 326 | }
|
| 327 | }
|
| 328 | }
|
| 329 |
|
| 330 | @Override
|
| 331 | public void postProcess(
|
| 332 | final WorldGenLevel level,
|
| 333 | final StructureManager structureManager,
|
| 334 | final ChunkGenerator generator,
|
| 335 | final RandomSource random,
|
| 336 | final BoundingBox chunkBB,
|
| 337 | final ChunkPos chunkPos,
|
| 338 | final BlockPos referencePos
|
| 339 | ) {
|
| 340 | int height = level.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, this.templatePosition.getX(), this.templatePosition.getZ());
|
| 341 | this.templatePosition = new BlockPos(this.templatePosition.getX(), height, this.templatePosition.getZ());
|
| 342 | BlockPos corner = StructureTemplate.transform(
|
| 343 | new BlockPos(this.template.getSize().getX() - 1, 0, this.template.getSize().getZ() - 1), Mirror.NONE, this.placeSettings.getRotation(), BlockPos.ZERO
|
| 344 | )
|
| 345 | .offset(this.templatePosition);
|
| 346 | this.templatePosition = new BlockPos(this.templatePosition.getX(), this.getHeight(this.templatePosition, level, corner), this.templatePosition.getZ());
|
| 347 | super.postProcess(level, structureManager, generator, random, chunkBB, chunkPos, referencePos);
|
| 348 | }
|
| 349 |
|
| 350 | private int getHeight(final BlockPos pos, final BlockGetter level, final BlockPos corner) {
|
| 351 | int newY = pos.getY();
|
| 352 | int minY = 512;
|
| 353 | int topY = newY - 1;
|
| 354 | int area = 0;
|
| 355 |
|
| 356 | for (BlockPos p : BlockPos.betweenClosed(pos, corner)) {
|
| 357 | int x = p.getX();
|
| 358 | int z = p.getZ();
|
| 359 | int floorY = pos.getY() - 1;
|
| 360 | BlockPos.MutableBlockPos tempPos = new BlockPos.MutableBlockPos(x, floorY, z);
|
| 361 | BlockState tempState = level.getBlockState(tempPos);
|
| 362 |
|
| 363 | for (FluidState tempFluid = level.getFluidState(tempPos);
|
| 364 | (tempState.isAir() || tempFluid.is(FluidTags.WATER) || tempState.is(BlockTags.ICE)) && floorY > level.getMinY() + 1;
|
| 365 | tempFluid = level.getFluidState(tempPos)
|
| 366 | ) {
|
| 367 | tempPos.set(x, --floorY, z);
|
| 368 | tempState = level.getBlockState(tempPos);
|
| 369 | }
|
| 370 |
|
| 371 | minY = Math.min(minY, floorY);
|
| 372 | if (floorY < topY - 2) {
|
| 373 | area++;
|
| 374 | }
|
| 375 | }
|
| 376 |
|
| 377 | int width = Math.abs(pos.getX() - corner.getX());
|
| 378 | if (topY - minY > 2 && area > width - 2) {
|
| 379 | newY = minY + 1;
|
| 380 | }
|
| 381 |
|
| 382 | return newY;
|
| 383 | }
|
| 384 | }
|
| 385 | }
|
| 386 |
|