From 4292485b64cec99bf65e208bc72faffd05bec67f Mon Sep 17 00:00:00 2001 From: Aeiou <3160746+AeiouEnigma@users.noreply.github.com> Date: Sat, 18 Dec 2021 17:37:42 -0500 Subject: [PATCH 1/8] Implement Starlight compatibility. --- build.gradle | 1 + .../structureMovement/ContraptionWorld.java | 10 ++++++ .../render/ContraptionRenderDispatcher.java | 2 +- .../PlacementSimulationWorld.java | 35 +++++++++++++++++-- .../worldWrappers/chunk/WrappedChunk.java | 15 ++++++-- 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 25b917f58..beb2fff1d 100644 --- a/build.gradle +++ b/build.gradle @@ -170,6 +170,7 @@ dependencies { compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}:api") runtimeOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}") + compileOnly fg.deobf("curse.maven:starlight-526854:3559934") // implementation fg.deobf("curse.maven:druidcraft-340991:3101903") // implementation fg.deobf("com.ferreusveritas.dynamictrees:DynamicTrees-1.16.5:0.10.0-Beta25") 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..d08a28337 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 @@ -46,4 +46,14 @@ 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_); } + + @Override + public int getMinBuildHeight() { + return -1 * (int)this.contraption.bounds.getYsize(); + } + + @Override + public int getHeight() { + return -2 * getMinBuildHeight(); + } } 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 59ef2e7eb..82f43ce96 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 @@ -104,7 +104,7 @@ public class ContraptionRenderDispatcher { } public static PlacementSimulationWorld setupRenderWorld(Level world, Contraption c) { - PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(world); + PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(world, c); renderWorld.setTileEntities(c.presentTileEntities.values()); 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 e97ec1adc..1f0b289d3 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 @@ -9,6 +9,8 @@ import java.util.function.Predicate; import com.jozufozu.flywheel.api.FlywheelWorld; +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; + import net.minecraft.core.BlockPos; import net.minecraft.core.SectionPos; import net.minecraft.world.level.Level; @@ -16,8 +18,12 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.lighting.LevelLightEngine; +import org.jetbrains.annotations.NotNull; + public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWorld { public Map blocksAdded; public Map tesAdded; @@ -27,12 +33,15 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo public WrappedChunkProvider chunkProvider; private final BlockPos.MutableBlockPos scratch = new BlockPos.MutableBlockPos(); - public PlacementSimulationWorld(Level wrapped) { - this(wrapped, new WrappedChunkProvider()); + private final Contraption contraption; + + public PlacementSimulationWorld(Level wrapped, Contraption c) { + this(wrapped, c, new WrappedChunkProvider()); } - public PlacementSimulationWorld(Level wrapped, WrappedChunkProvider chunkProvider) { + public PlacementSimulationWorld(Level wrapped, @NotNull Contraption c, WrappedChunkProvider chunkProvider) { super(wrapped, chunkProvider); + contraption = c; this.chunkProvider = chunkProvider.setPlacementWorld(this); spannedSections = new HashSet<>(); lighter = new LevelLightEngine(chunkProvider, true, false); // blockLight, skyLight @@ -117,4 +126,24 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo return state; return Blocks.AIR.defaultBlockState(); } + + @Override + public int getMinBuildHeight() { + return contraption.getContraptionWorld().getMinBuildHeight(); + } + + @Override + public int getHeight() { + return contraption.getContraptionWorld().getHeight(); + } + + // Override Starlight's ExtendedWorld interface methods: + + public LevelChunk getChunkAtImmediately(final int chunkX, final int chunkZ) { + return chunkProvider.getChunk(chunkX, chunkZ, false); + } + + public ChunkAccess getAnyChunkImmediately(final int chunkX, final int chunkZ) { + return chunkProvider.getChunk(chunkX, chunkZ); + } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java index fbca9d03b..60dbcd16b 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java @@ -7,6 +7,10 @@ import java.util.stream.Stream; import javax.annotation.Nullable; +import ca.spottedleaf.starlight.common.chunk.ExtendedChunk; + +import ca.spottedleaf.starlight.common.light.StarLightEngine; + import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import it.unimi.dsi.fastutil.longs.LongSet; @@ -30,6 +34,7 @@ import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.ticks.BlackholeTickAccess; import net.minecraft.world.ticks.TickContainerAccess; +import net.minecraftforge.fml.ModList; public class WrappedChunk extends ChunkAccess { @@ -50,11 +55,17 @@ public class WrappedChunk extends ChunkAccess { this.x = x; this.z = z; - this.sections = new LevelChunkSection[16]; + // Do not hard code the number of chunk sections + this.sections = new LevelChunkSection[world.getSectionsCount()]; - for (int i = 0; i < 16; i++) { + for (int i = 0; i < this.sections.length; i++) { sections[i] = new WrappedChunkSection(this, i << 4); } + // If Starlight is loaded, initialize its NibbleArrays for this chunk to default values + if (ModList.get().isLoaded("starlight")) { + ((ExtendedChunk)this).setBlockNibbles(StarLightEngine.getFilledEmptyLight(this)); + ((ExtendedChunk)this).setSkyNibbles(StarLightEngine.getFilledEmptyLight(this)); + } } @Override From 56fd2e0a636582f934f5fdf02079200f3f9d6029 Mon Sep 17 00:00:00 2001 From: Aeiou <3160746+AeiouEnigma@users.noreply.github.com> Date: Sun, 19 Dec 2021 17:17:17 -0500 Subject: [PATCH 2/8] Change from jetbrains @NotNull to javax @Nonnull annotation in PlacementSimulationWorld --- .../utility/worldWrappers/PlacementSimulationWorld.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 1f0b289d3..60410efd9 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 @@ -22,7 +22,7 @@ import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.lighting.LevelLightEngine; -import org.jetbrains.annotations.NotNull; +import javax.annotation.Nonnull; public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWorld { public Map blocksAdded; @@ -39,7 +39,7 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo this(wrapped, c, new WrappedChunkProvider()); } - public PlacementSimulationWorld(Level wrapped, @NotNull Contraption c, WrappedChunkProvider chunkProvider) { + public PlacementSimulationWorld(Level wrapped, @Nonnull Contraption c, WrappedChunkProvider chunkProvider) { super(wrapped, chunkProvider); contraption = c; this.chunkProvider = chunkProvider.setPlacementWorld(this); From 3415ba97ac9597ca79f68c3ccb17ba43386bbe17 Mon Sep 17 00:00:00 2001 From: Aeiou <3160746+AeiouEnigma@users.noreply.github.com> Date: Sun, 19 Dec 2021 18:43:38 -0500 Subject: [PATCH 3/8] Add Starlight to Mods enum, along with an executeIfInstalled method. Use said method in WrappedChunk in place of an if-statement to execute Starlight-dependent code --- src/main/java/com/simibubi/create/compat/Mods.java | 11 +++++++++++ .../utility/worldWrappers/chunk/WrappedChunk.java | 7 ++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/Mods.java b/src/main/java/com/simibubi/create/compat/Mods.java index b32960505..6f6684554 100644 --- a/src/main/java/com/simibubi/create/compat/Mods.java +++ b/src/main/java/com/simibubi/create/compat/Mods.java @@ -12,6 +12,7 @@ import net.minecraftforge.fml.ModList; */ public enum Mods { DYNAMICTREES, + STARLIGHT, TCONSTRUCT; /** @@ -38,4 +39,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/foundation/utility/worldWrappers/chunk/WrappedChunk.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java index 60dbcd16b..cb12d4c83 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java @@ -11,6 +11,7 @@ import ca.spottedleaf.starlight.common.chunk.ExtendedChunk; import ca.spottedleaf.starlight.common.light.StarLightEngine; +import com.simibubi.create.compat.Mods; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import it.unimi.dsi.fastutil.longs.LongSet; @@ -34,7 +35,6 @@ import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.ticks.BlackholeTickAccess; import net.minecraft.world.ticks.TickContainerAccess; -import net.minecraftforge.fml.ModList; public class WrappedChunk extends ChunkAccess { @@ -61,11 +61,12 @@ public class WrappedChunk extends ChunkAccess { for (int i = 0; i < this.sections.length; i++) { sections[i] = new WrappedChunkSection(this, i << 4); } + // If Starlight is loaded, initialize its NibbleArrays for this chunk to default values - if (ModList.get().isLoaded("starlight")) { + Mods.STARLIGHT.executeIfInstalled(() -> () -> { ((ExtendedChunk)this).setBlockNibbles(StarLightEngine.getFilledEmptyLight(this)); ((ExtendedChunk)this).setSkyNibbles(StarLightEngine.getFilledEmptyLight(this)); - } + }); } @Override From 6938bc2e063df2e2424ffd84d6c75c736af2016c Mon Sep 17 00:00:00 2001 From: Aeiou <3160746+AeiouEnigma@users.noreply.github.com> Date: Sat, 18 Dec 2021 17:37:42 -0500 Subject: [PATCH 4/8] Implement Starlight compatibility. --- build.gradle | 1 + .../structureMovement/ContraptionWorld.java | 10 ++++++ .../render/ContraptionRenderDispatcher.java | 2 +- .../PlacementSimulationWorld.java | 35 +++++++++++++++++-- .../worldWrappers/chunk/WrappedChunk.java | 15 ++++++-- 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 25b917f58..beb2fff1d 100644 --- a/build.gradle +++ b/build.gradle @@ -170,6 +170,7 @@ dependencies { compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}:api") runtimeOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}") + compileOnly fg.deobf("curse.maven:starlight-526854:3559934") // implementation fg.deobf("curse.maven:druidcraft-340991:3101903") // implementation fg.deobf("com.ferreusveritas.dynamictrees:DynamicTrees-1.16.5:0.10.0-Beta25") 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..d08a28337 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 @@ -46,4 +46,14 @@ 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_); } + + @Override + public int getMinBuildHeight() { + return -1 * (int)this.contraption.bounds.getYsize(); + } + + @Override + public int getHeight() { + return -2 * getMinBuildHeight(); + } } 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 59ef2e7eb..82f43ce96 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 @@ -104,7 +104,7 @@ public class ContraptionRenderDispatcher { } public static PlacementSimulationWorld setupRenderWorld(Level world, Contraption c) { - PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(world); + PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(world, c); renderWorld.setTileEntities(c.presentTileEntities.values()); 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 e97ec1adc..1f0b289d3 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 @@ -9,6 +9,8 @@ import java.util.function.Predicate; import com.jozufozu.flywheel.api.FlywheelWorld; +import com.simibubi.create.content.contraptions.components.structureMovement.Contraption; + import net.minecraft.core.BlockPos; import net.minecraft.core.SectionPos; import net.minecraft.world.level.Level; @@ -16,8 +18,12 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.ChunkAccess; +import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.lighting.LevelLightEngine; +import org.jetbrains.annotations.NotNull; + public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWorld { public Map blocksAdded; public Map tesAdded; @@ -27,12 +33,15 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo public WrappedChunkProvider chunkProvider; private final BlockPos.MutableBlockPos scratch = new BlockPos.MutableBlockPos(); - public PlacementSimulationWorld(Level wrapped) { - this(wrapped, new WrappedChunkProvider()); + private final Contraption contraption; + + public PlacementSimulationWorld(Level wrapped, Contraption c) { + this(wrapped, c, new WrappedChunkProvider()); } - public PlacementSimulationWorld(Level wrapped, WrappedChunkProvider chunkProvider) { + public PlacementSimulationWorld(Level wrapped, @NotNull Contraption c, WrappedChunkProvider chunkProvider) { super(wrapped, chunkProvider); + contraption = c; this.chunkProvider = chunkProvider.setPlacementWorld(this); spannedSections = new HashSet<>(); lighter = new LevelLightEngine(chunkProvider, true, false); // blockLight, skyLight @@ -117,4 +126,24 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo return state; return Blocks.AIR.defaultBlockState(); } + + @Override + public int getMinBuildHeight() { + return contraption.getContraptionWorld().getMinBuildHeight(); + } + + @Override + public int getHeight() { + return contraption.getContraptionWorld().getHeight(); + } + + // Override Starlight's ExtendedWorld interface methods: + + public LevelChunk getChunkAtImmediately(final int chunkX, final int chunkZ) { + return chunkProvider.getChunk(chunkX, chunkZ, false); + } + + public ChunkAccess getAnyChunkImmediately(final int chunkX, final int chunkZ) { + return chunkProvider.getChunk(chunkX, chunkZ); + } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java index fbca9d03b..60dbcd16b 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java @@ -7,6 +7,10 @@ import java.util.stream.Stream; import javax.annotation.Nullable; +import ca.spottedleaf.starlight.common.chunk.ExtendedChunk; + +import ca.spottedleaf.starlight.common.light.StarLightEngine; + import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import it.unimi.dsi.fastutil.longs.LongSet; @@ -30,6 +34,7 @@ import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.ticks.BlackholeTickAccess; import net.minecraft.world.ticks.TickContainerAccess; +import net.minecraftforge.fml.ModList; public class WrappedChunk extends ChunkAccess { @@ -50,11 +55,17 @@ public class WrappedChunk extends ChunkAccess { this.x = x; this.z = z; - this.sections = new LevelChunkSection[16]; + // Do not hard code the number of chunk sections + this.sections = new LevelChunkSection[world.getSectionsCount()]; - for (int i = 0; i < 16; i++) { + for (int i = 0; i < this.sections.length; i++) { sections[i] = new WrappedChunkSection(this, i << 4); } + // If Starlight is loaded, initialize its NibbleArrays for this chunk to default values + if (ModList.get().isLoaded("starlight")) { + ((ExtendedChunk)this).setBlockNibbles(StarLightEngine.getFilledEmptyLight(this)); + ((ExtendedChunk)this).setSkyNibbles(StarLightEngine.getFilledEmptyLight(this)); + } } @Override From 11e6c3f45aa21bfa15bccdeda351e6e883e7bb6c Mon Sep 17 00:00:00 2001 From: Aeiou <3160746+AeiouEnigma@users.noreply.github.com> Date: Sun, 19 Dec 2021 17:17:17 -0500 Subject: [PATCH 5/8] Change from jetbrains @NotNull to javax @Nonnull annotation in PlacementSimulationWorld --- .../utility/worldWrappers/PlacementSimulationWorld.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 1f0b289d3..60410efd9 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 @@ -22,7 +22,7 @@ import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.lighting.LevelLightEngine; -import org.jetbrains.annotations.NotNull; +import javax.annotation.Nonnull; public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWorld { public Map blocksAdded; @@ -39,7 +39,7 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo this(wrapped, c, new WrappedChunkProvider()); } - public PlacementSimulationWorld(Level wrapped, @NotNull Contraption c, WrappedChunkProvider chunkProvider) { + public PlacementSimulationWorld(Level wrapped, @Nonnull Contraption c, WrappedChunkProvider chunkProvider) { super(wrapped, chunkProvider); contraption = c; this.chunkProvider = chunkProvider.setPlacementWorld(this); From 7fd531199c74d6550d4272e37fc4cc374987758d Mon Sep 17 00:00:00 2001 From: Aeiou <3160746+AeiouEnigma@users.noreply.github.com> Date: Sun, 19 Dec 2021 18:43:38 -0500 Subject: [PATCH 6/8] Add Starlight to Mods enum, along with an executeIfInstalled method. Use said method in WrappedChunk in place of an if-statement to execute Starlight-dependent code --- src/main/java/com/simibubi/create/compat/Mods.java | 11 +++++++++++ .../utility/worldWrappers/chunk/WrappedChunk.java | 7 ++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/compat/Mods.java b/src/main/java/com/simibubi/create/compat/Mods.java index b32960505..6f6684554 100644 --- a/src/main/java/com/simibubi/create/compat/Mods.java +++ b/src/main/java/com/simibubi/create/compat/Mods.java @@ -12,6 +12,7 @@ import net.minecraftforge.fml.ModList; */ public enum Mods { DYNAMICTREES, + STARLIGHT, TCONSTRUCT; /** @@ -38,4 +39,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/foundation/utility/worldWrappers/chunk/WrappedChunk.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java index 60dbcd16b..cb12d4c83 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java @@ -11,6 +11,7 @@ import ca.spottedleaf.starlight.common.chunk.ExtendedChunk; import ca.spottedleaf.starlight.common.light.StarLightEngine; +import com.simibubi.create.compat.Mods; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import it.unimi.dsi.fastutil.longs.LongSet; @@ -34,7 +35,6 @@ import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.ticks.BlackholeTickAccess; import net.minecraft.world.ticks.TickContainerAccess; -import net.minecraftforge.fml.ModList; public class WrappedChunk extends ChunkAccess { @@ -61,11 +61,12 @@ public class WrappedChunk extends ChunkAccess { for (int i = 0; i < this.sections.length; i++) { sections[i] = new WrappedChunkSection(this, i << 4); } + // If Starlight is loaded, initialize its NibbleArrays for this chunk to default values - if (ModList.get().isLoaded("starlight")) { + Mods.STARLIGHT.executeIfInstalled(() -> () -> { ((ExtendedChunk)this).setBlockNibbles(StarLightEngine.getFilledEmptyLight(this)); ((ExtendedChunk)this).setSkyNibbles(StarLightEngine.getFilledEmptyLight(this)); - } + }); } @Override From 5e09cc3de2bd1687b2a4f31e9e2482ffa27c93e5 Mon Sep 17 00:00:00 2001 From: Aeiou <3160746+AeiouEnigma@users.noreply.github.com> Date: Mon, 20 Dec 2021 11:56:12 -0500 Subject: [PATCH 7/8] Use implementation instead of compileOnly for starlight in build.gradle --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index beb2fff1d..bdc52ff63 100644 --- a/build.gradle +++ b/build.gradle @@ -170,7 +170,7 @@ dependencies { compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}:api") runtimeOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}") - compileOnly fg.deobf("curse.maven:starlight-526854:3559934") + implementation fg.deobf("curse.maven:starlight-526854:3559934") // implementation fg.deobf("curse.maven:druidcraft-340991:3101903") // implementation fg.deobf("com.ferreusveritas.dynamictrees:DynamicTrees-1.16.5:0.10.0-Beta25") From e6c99b250e489562bae8729fadef087801d9eddf Mon Sep 17 00:00:00 2001 From: Aeiou <3160746+AeiouEnigma@users.noreply.github.com> Date: Mon, 20 Dec 2021 16:43:06 -0500 Subject: [PATCH 8/8] 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 --- .../structureMovement/ContraptionWorld.java | 11 +++-- .../PlacementSimulationWorld.java | 14 +++--- .../utility/worldWrappers/WrappedWorld.java | 48 ++++++++++++++++++- 3 files changed, 62 insertions(+), 11 deletions(-) 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(); + } }