diff --git a/gradle.properties b/gradle.properties index 54ad980d4..c13670115 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,7 +19,7 @@ parchment_version = 2021.12.19 # dependency versions registrate_version = MC1.18-1.0.21 -flywheel_version = 1.18-0.5.0.30 +flywheel_version = 1.18-0.5.0.31 jei_minecraft_version = 1.18 jei_version = 9.0.0.40 diff --git a/src/main/java/com/simibubi/create/compat/Mods.java b/src/main/java/com/simibubi/create/compat/Mods.java index b32960505..1aba89709 100644 --- a/src/main/java/com/simibubi/create/compat/Mods.java +++ b/src/main/java/com/simibubi/create/compat/Mods.java @@ -38,4 +38,14 @@ public enum Mods { return Optional.of(toRun.get().get()); return Optional.empty(); } + + /** + * Simple hook to execute code if a mod is installed + * @param toExecute will be executed only if the mod is loaded + */ + public void executeIfInstalled(Supplier toExecute) { + if (isLoaded()) { + toExecute.get().run(); + } + } } 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 16abe0041..8e48ab7cd 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 @@ -21,7 +21,6 @@ public class ContraptionWorld extends WrappedWorld { this.contraption = contraption; } - @Override public BlockState getBlockState(BlockPos pos) { StructureTemplate.StructureBlockInfo blockInfo = contraption.getBlocks().get(pos); @@ -46,4 +45,16 @@ public class ContraptionWorld extends WrappedWorld { public void playLocalSound(double x, double y, double z, SoundEvent p_184134_7_, SoundSource p_184134_8_, float p_184134_9_, float p_184134_10_, boolean p_184134_11_) { world.playLocalSound(x, y, z, p_184134_7_, p_184134_8_, p_184134_9_, p_184134_10_, p_184134_11_); } + + // Calculate lazily to avoid issues on load when the bounds are yet to be determined. + + @Override + public int getHeight() { + return getMinBuildHeight() * (-2); + } + + @Override + public int getMinBuildHeight() { + return - (int) contraption.bounds.getYsize() + 1; + } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java index 47486e234..906ad3170 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderDispatcher.java @@ -19,6 +19,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllMovementBehaviours; import com.simibubi.create.content.contraptions.components.structureMovement.AbstractContraptionEntity; import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; +import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionWorld; import com.simibubi.create.content.contraptions.components.structureMovement.MovementBehaviour; import com.simibubi.create.content.contraptions.components.structureMovement.MovementContext; import com.simibubi.create.foundation.render.SuperByteBuffer; @@ -104,7 +105,8 @@ public class ContraptionRenderDispatcher { } public static VirtualRenderWorld setupRenderWorld(Level world, Contraption c) { - VirtualRenderWorld renderWorld = new VirtualRenderWorld(world); + ContraptionWorld contraptionWorld = c.getContraptionWorld(); + VirtualRenderWorld renderWorld = new VirtualRenderWorld(world, contraptionWorld.getHeight(), contraptionWorld.getMinBuildHeight()); renderWorld.setTileEntities(c.presentTileEntities.values()); 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 d6b4b418b..f9dfd055e 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 @@ -9,6 +9,7 @@ import javax.annotation.Nullable; 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; @@ -198,4 +199,51 @@ public class WrappedWorld extends Level { protected LevelEntityGetter getEntities() { return entityGetter; } + + // Intentionally copied from LevelHeightAccessor. Lithium overrides these methods so we need to, too. + + @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(); + } }