Add more LevelHeightAccessor Overrides to WrappedWorld to avoid logical conflicts with other mods which may make changes to the default vanilla implementations of these methods. In particular, Create Refabricated would conflict with Lithium if Starlight was installed. These changes prevent such an issue from occurring if a Forge mod were to attempt a similar optimization to Lithium's, where Level heights are assumed to behave in predictable, static ways
This commit is contained in:
parent
5e09cc3de2
commit
e6c99b250e
3 changed files with 62 additions and 11 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<Block> getBlockTicks() {
|
||||
return world.getBlockTicks();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LevelTickAccess<Fluid> getFluidTicks() {
|
||||
return world.getFluidTicks();
|
||||
|
@ -202,4 +203,49 @@ public class WrappedWorld extends Level {
|
|||
protected LevelEntityGetter<Entity> 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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue