From 34c924d7583a153ab037bf585a2b687a7c9bb2dd Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 16 Feb 2019 18:01:43 +0200 Subject: [PATCH] Fixed the offsetting problem --- .../unicopia/structure/AbstractFeature.java | 29 +++++++++++++------ .../unicopia/structure/CloudDungeon.java | 10 ++++--- .../structure/TemplateBasedFeature.java | 2 +- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/structure/AbstractFeature.java b/src/main/java/com/minelittlepony/unicopia/structure/AbstractFeature.java index f2512437..c103bb93 100644 --- a/src/main/java/com/minelittlepony/unicopia/structure/AbstractFeature.java +++ b/src/main/java/com/minelittlepony/unicopia/structure/AbstractFeature.java @@ -21,7 +21,7 @@ public abstract class AbstractFeature extends StructureComponent { protected int depth; - protected int horizontalPos = -1; + protected int verticalPos = -1; public AbstractFeature() { } @@ -47,7 +47,7 @@ public abstract class AbstractFeature extends StructureComponent { tagCompound.setInteger("Width", width); tagCompound.setInteger("Height", height); tagCompound.setInteger("Depth", depth); - tagCompound.setInteger("HPos", horizontalPos); + tagCompound.setInteger("HPos", verticalPos); } @Override @@ -55,15 +55,25 @@ public abstract class AbstractFeature extends StructureComponent { width = tagCompound.getInteger("Width"); height = tagCompound.getInteger("Height"); depth = tagCompound.getInteger("Depth"); - horizontalPos = tagCompound.getInteger("HPos"); + verticalPos = tagCompound.getInteger("HPos"); } protected int getAverageStructureAltitude() { return 64; } - protected boolean offsetToAverageGroundLevel(World worldIn, StructureBoundingBox structurebb, int yOffset) { - if (horizontalPos >= 0) { + /** + * Offsets this component to the average ground level, sliding it down hill if needed. + * Called to make structures 'lay on top' of the land and also prevent floating houses. + * + * @param world The world + * @param bounds The structure bounding box + * @param yOffset Offset from ground level. (default: -1) + * + * @return Trues true if we can generate here. + */ + protected boolean tryFitTerrain(World world, StructureBoundingBox bounds, int yOffset) { + if (verticalPos >= 0) { return true; } @@ -78,8 +88,8 @@ public abstract class AbstractFeature extends StructureComponent { for (int x = boundingBox.minX; x <= boundingBox.maxX; ++x) { pos.setPos(x, targetY, z); - if (structurebb.isVecInside(pos)) { - xOff += Math.max(worldIn.getTopSolidOrLiquidBlock(pos).getY(), worldIn.provider.getAverageGroundLevel()); + if (bounds.isVecInside(pos)) { + xOff += Math.max(world.getTopSolidOrLiquidBlock(pos).getY(), world.provider.getAverageGroundLevel()); offsetIncrements++; } } @@ -89,8 +99,9 @@ public abstract class AbstractFeature extends StructureComponent { return false; } - horizontalPos = xOff / offsetIncrements; - boundingBox.offset(0, horizontalPos - boundingBox.minY + yOffset, 0); + verticalPos = xOff / offsetIncrements; + boundingBox.offset(0, verticalPos - boundingBox.minY + yOffset, 0); + return true; } diff --git a/src/main/java/com/minelittlepony/unicopia/structure/CloudDungeon.java b/src/main/java/com/minelittlepony/unicopia/structure/CloudDungeon.java index 9c6baadd..6513bac4 100644 --- a/src/main/java/com/minelittlepony/unicopia/structure/CloudDungeon.java +++ b/src/main/java/com/minelittlepony/unicopia/structure/CloudDungeon.java @@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.Unicopia; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.gen.structure.StructureBoundingBox; import net.minecraft.world.gen.structure.template.PlacementSettings; import net.minecraft.world.gen.structure.template.TemplateManager; @@ -24,12 +25,13 @@ public class CloudDungeon extends TemplateBasedFeature { @Override public boolean addComponentParts(World world, BlockPos startPos, TemplateManager templates, PlacementSettings placement) { - if (startPos.getY() < 200) { - startPos = new BlockPos(startPos.getX(), 200, startPos.getZ()); - } - applyTemplate(world, startPos, templates, placement, STRUCTURE); return true; } + + @Override + protected boolean tryFitTerrain(World world, StructureBoundingBox bounds, int yOffset) { + return true; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/structure/TemplateBasedFeature.java b/src/main/java/com/minelittlepony/unicopia/structure/TemplateBasedFeature.java index c5b80a00..ef645e28 100644 --- a/src/main/java/com/minelittlepony/unicopia/structure/TemplateBasedFeature.java +++ b/src/main/java/com/minelittlepony/unicopia/structure/TemplateBasedFeature.java @@ -31,7 +31,7 @@ public abstract class TemplateBasedFeature extends AbstractFeature { @Override public boolean addComponentParts(World world, Random rand, StructureBoundingBox bounds) { - if (!offsetToAverageGroundLevel(world, bounds, -1)) { + if (!tryFitTerrain(world, bounds, -1)) { return false; }