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