diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionWorld.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionWorld.java index d08a28337..da09487b1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionWorld.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/ContraptionWorld.java @@ -14,11 +14,14 @@ import net.minecraft.world.phys.Vec3; public class ContraptionWorld extends WrappedWorld { final Contraption contraption; + private final int minBuildHeight, height; public ContraptionWorld(Level world, Contraption contraption) { super(world); this.contraption = contraption; + minBuildHeight = - (int) contraption.bounds.getYsize() + 1; + height = minBuildHeight * (-2); } @@ -48,12 +51,12 @@ public class ContraptionWorld extends WrappedWorld { } @Override - public int getMinBuildHeight() { - return -1 * (int)this.contraption.bounds.getYsize(); + public int getHeight() { + return this.height; } @Override - public int getHeight() { - return -2 * getMinBuildHeight(); + public int getMinBuildHeight() { + return this.minBuildHeight; } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java index 60410efd9..a3030eaff 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/PlacementSimulationWorld.java @@ -11,6 +11,8 @@ import com.jozufozu.flywheel.api.FlywheelWorld; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionWorld; + import net.minecraft.core.BlockPos; import net.minecraft.core.SectionPos; import net.minecraft.world.level.Level; @@ -33,7 +35,7 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo public WrappedChunkProvider chunkProvider; private final BlockPos.MutableBlockPos scratch = new BlockPos.MutableBlockPos(); - private final Contraption contraption; + private final ContraptionWorld contraptionWorld; public PlacementSimulationWorld(Level wrapped, Contraption c) { this(wrapped, c, new WrappedChunkProvider()); @@ -41,7 +43,7 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo public PlacementSimulationWorld(Level wrapped, @Nonnull Contraption c, WrappedChunkProvider chunkProvider) { super(wrapped, chunkProvider); - contraption = c; + contraptionWorld = c.getContraptionWorld(); this.chunkProvider = chunkProvider.setPlacementWorld(this); spannedSections = new HashSet<>(); lighter = new LevelLightEngine(chunkProvider, true, false); // blockLight, skyLight @@ -128,13 +130,13 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo } @Override - public int getMinBuildHeight() { - return contraption.getContraptionWorld().getMinBuildHeight(); + public int getHeight() { + return contraptionWorld.getHeight(); } @Override - public int getHeight() { - return contraption.getContraptionWorld().getHeight(); + public int getMinBuildHeight() { + return contraptionWorld.getMinBuildHeight(); } // Override Starlight's ExtendedWorld interface methods: diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java index fe405971a..802268f3b 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedWorld.java @@ -11,6 +11,7 @@ import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.RegistryAccess; +import net.minecraft.core.SectionPos; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.tags.TagContainer; @@ -95,7 +96,7 @@ public class WrappedWorld extends Level { public LevelTickAccess getBlockTicks() { return world.getBlockTicks(); } - + @Override public LevelTickAccess getFluidTicks() { return world.getFluidTicks(); @@ -202,4 +203,49 @@ public class WrappedWorld extends Level { protected LevelEntityGetter getEntities() { return entityGetter; } + + @Override + public int getMaxBuildHeight() { + return this.getMinBuildHeight() + this.getHeight(); + } + + @Override + public int getSectionsCount() { + return this.getMaxSection() - this.getMinSection(); + } + + @Override + public int getMinSection() { + return SectionPos.blockToSectionCoord(this.getMinBuildHeight()); + } + + @Override + public int getMaxSection() { + return SectionPos.blockToSectionCoord(this.getMaxBuildHeight() - 1) + 1; + } + + @Override + public boolean isOutsideBuildHeight(BlockPos pos) { + return this.isOutsideBuildHeight(pos.getY()); + } + + @Override + public boolean isOutsideBuildHeight(int y) { + return y < this.getMinBuildHeight() || y >= this.getMaxBuildHeight(); + } + + @Override + public int getSectionIndex(int y) { + return this.getSectionIndexFromSectionY(SectionPos.blockToSectionCoord(y)); + } + + @Override + public int getSectionIndexFromSectionY(int sectionY) { + return sectionY - this.getMinSection(); + } + + @Override + public int getSectionYFromSectionIndex(int sectionIndex) { + return sectionIndex + this.getMinSection(); + } }