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:
Aeiou 2021-12-20 16:43:06 -05:00
parent 5e09cc3de2
commit e6c99b250e
3 changed files with 62 additions and 11 deletions

View file

@ -14,11 +14,14 @@ import net.minecraft.world.phys.Vec3;
public class ContraptionWorld extends WrappedWorld { public class ContraptionWorld extends WrappedWorld {
final Contraption contraption; final Contraption contraption;
private final int minBuildHeight, height;
public ContraptionWorld(Level world, Contraption contraption) { public ContraptionWorld(Level world, Contraption contraption) {
super(world); super(world);
this.contraption = contraption; this.contraption = contraption;
minBuildHeight = - (int) contraption.bounds.getYsize() + 1;
height = minBuildHeight * (-2);
} }
@ -48,12 +51,12 @@ public class ContraptionWorld extends WrappedWorld {
} }
@Override @Override
public int getMinBuildHeight() { public int getHeight() {
return -1 * (int)this.contraption.bounds.getYsize(); return this.height;
} }
@Override @Override
public int getHeight() { public int getMinBuildHeight() {
return -2 * getMinBuildHeight(); return this.minBuildHeight;
} }
} }

View file

@ -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.Contraption;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionWorld;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos; import net.minecraft.core.SectionPos;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
@ -33,7 +35,7 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo
public WrappedChunkProvider chunkProvider; public WrappedChunkProvider chunkProvider;
private final BlockPos.MutableBlockPos scratch = new BlockPos.MutableBlockPos(); private final BlockPos.MutableBlockPos scratch = new BlockPos.MutableBlockPos();
private final Contraption contraption; private final ContraptionWorld contraptionWorld;
public PlacementSimulationWorld(Level wrapped, Contraption c) { public PlacementSimulationWorld(Level wrapped, Contraption c) {
this(wrapped, c, new WrappedChunkProvider()); 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) { public PlacementSimulationWorld(Level wrapped, @Nonnull Contraption c, WrappedChunkProvider chunkProvider) {
super(wrapped, chunkProvider); super(wrapped, chunkProvider);
contraption = c; contraptionWorld = c.getContraptionWorld();
this.chunkProvider = chunkProvider.setPlacementWorld(this); this.chunkProvider = chunkProvider.setPlacementWorld(this);
spannedSections = new HashSet<>(); spannedSections = new HashSet<>();
lighter = new LevelLightEngine(chunkProvider, true, false); // blockLight, skyLight lighter = new LevelLightEngine(chunkProvider, true, false); // blockLight, skyLight
@ -128,13 +130,13 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo
} }
@Override @Override
public int getMinBuildHeight() { public int getHeight() {
return contraption.getContraptionWorld().getMinBuildHeight(); return contraptionWorld.getHeight();
} }
@Override @Override
public int getHeight() { public int getMinBuildHeight() {
return contraption.getContraptionWorld().getHeight(); return contraptionWorld.getMinBuildHeight();
} }
// Override Starlight's ExtendedWorld interface methods: // Override Starlight's ExtendedWorld interface methods:

View file

@ -11,6 +11,7 @@ import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.core.SectionPos;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.TagContainer; import net.minecraft.tags.TagContainer;
@ -95,7 +96,7 @@ public class WrappedWorld extends Level {
public LevelTickAccess<Block> getBlockTicks() { public LevelTickAccess<Block> getBlockTicks() {
return world.getBlockTicks(); return world.getBlockTicks();
} }
@Override @Override
public LevelTickAccess<Fluid> getFluidTicks() { public LevelTickAccess<Fluid> getFluidTicks() {
return world.getFluidTicks(); return world.getFluidTicks();
@ -202,4 +203,49 @@ public class WrappedWorld extends Level {
protected LevelEntityGetter<Entity> getEntities() { protected LevelEntityGetter<Entity> getEntities() {
return entityGetter; 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();
}
} }