mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-30 16:28:00 +01:00
Fixed the offsetting problem
This commit is contained in:
parent
31e92ac25f
commit
34c924d758
3 changed files with 27 additions and 14 deletions
|
@ -21,7 +21,7 @@ public abstract class AbstractFeature extends StructureComponent {
|
||||||
|
|
||||||
protected int depth;
|
protected int depth;
|
||||||
|
|
||||||
protected int horizontalPos = -1;
|
protected int verticalPos = -1;
|
||||||
|
|
||||||
public AbstractFeature() {
|
public AbstractFeature() {
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public abstract class AbstractFeature extends StructureComponent {
|
||||||
tagCompound.setInteger("Width", width);
|
tagCompound.setInteger("Width", width);
|
||||||
tagCompound.setInteger("Height", height);
|
tagCompound.setInteger("Height", height);
|
||||||
tagCompound.setInteger("Depth", depth);
|
tagCompound.setInteger("Depth", depth);
|
||||||
tagCompound.setInteger("HPos", horizontalPos);
|
tagCompound.setInteger("HPos", verticalPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,15 +55,25 @@ public abstract class AbstractFeature extends StructureComponent {
|
||||||
width = tagCompound.getInteger("Width");
|
width = tagCompound.getInteger("Width");
|
||||||
height = tagCompound.getInteger("Height");
|
height = tagCompound.getInteger("Height");
|
||||||
depth = tagCompound.getInteger("Depth");
|
depth = tagCompound.getInteger("Depth");
|
||||||
horizontalPos = tagCompound.getInteger("HPos");
|
verticalPos = tagCompound.getInteger("HPos");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getAverageStructureAltitude() {
|
protected int getAverageStructureAltitude() {
|
||||||
return 64;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +88,8 @@ public abstract class AbstractFeature extends StructureComponent {
|
||||||
for (int x = boundingBox.minX; x <= boundingBox.maxX; ++x) {
|
for (int x = boundingBox.minX; x <= boundingBox.maxX; ++x) {
|
||||||
pos.setPos(x, targetY, z);
|
pos.setPos(x, targetY, z);
|
||||||
|
|
||||||
if (structurebb.isVecInside(pos)) {
|
if (bounds.isVecInside(pos)) {
|
||||||
xOff += Math.max(worldIn.getTopSolidOrLiquidBlock(pos).getY(), worldIn.provider.getAverageGroundLevel());
|
xOff += Math.max(world.getTopSolidOrLiquidBlock(pos).getY(), world.provider.getAverageGroundLevel());
|
||||||
offsetIncrements++;
|
offsetIncrements++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,8 +99,9 @@ public abstract class AbstractFeature extends StructureComponent {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
horizontalPos = xOff / offsetIncrements;
|
verticalPos = xOff / offsetIncrements;
|
||||||
boundingBox.offset(0, horizontalPos - boundingBox.minY + yOffset, 0);
|
boundingBox.offset(0, verticalPos - boundingBox.minY + yOffset, 0);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.Unicopia;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
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.PlacementSettings;
|
||||||
import net.minecraft.world.gen.structure.template.TemplateManager;
|
import net.minecraft.world.gen.structure.template.TemplateManager;
|
||||||
|
|
||||||
|
@ -24,12 +25,13 @@ public class CloudDungeon extends TemplateBasedFeature {
|
||||||
@Override
|
@Override
|
||||||
public boolean addComponentParts(World world, BlockPos startPos, TemplateManager templates, PlacementSettings placement) {
|
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);
|
applyTemplate(world, startPos, templates, placement, STRUCTURE);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean tryFitTerrain(World world, StructureBoundingBox bounds, int yOffset) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ public abstract class TemplateBasedFeature extends AbstractFeature {
|
||||||
@Override
|
@Override
|
||||||
public boolean addComponentParts(World world, Random rand, StructureBoundingBox bounds) {
|
public boolean addComponentParts(World world, Random rand, StructureBoundingBox bounds) {
|
||||||
|
|
||||||
if (!offsetToAverageGroundLevel(world, bounds, -1)) {
|
if (!tryFitTerrain(world, bounds, -1)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue