Fixed the offsetting problem

This commit is contained in:
Sollace 2019-02-16 18:01:43 +02:00
parent 31e92ac25f
commit 34c924d758
3 changed files with 27 additions and 14 deletions

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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;
}