Implement Starlight compatibility.

This commit is contained in:
Aeiou 2021-12-18 17:37:42 -05:00
parent c5a3306d56
commit 6938bc2e06
5 changed files with 57 additions and 6 deletions

View file

@ -170,6 +170,7 @@ dependencies {
compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}:api") compileOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}:api")
runtimeOnly fg.deobf("mezz.jei:jei-${jei_minecraft_version}:${jei_version}") 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("curse.maven:druidcraft-340991:3101903")
// implementation fg.deobf("com.ferreusveritas.dynamictrees:DynamicTrees-1.16.5:0.10.0-Beta25") // implementation fg.deobf("com.ferreusveritas.dynamictrees:DynamicTrees-1.16.5:0.10.0-Beta25")

View file

@ -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_) { 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_); 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();
}
} }

View file

@ -104,7 +104,7 @@ public class ContraptionRenderDispatcher {
} }
public static PlacementSimulationWorld setupRenderWorld(Level world, Contraption c) { public static PlacementSimulationWorld setupRenderWorld(Level world, Contraption c) {
PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(world); PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(world, c);
renderWorld.setTileEntities(c.presentTileEntities.values()); renderWorld.setTileEntities(c.presentTileEntities.values());

View file

@ -9,6 +9,8 @@ import java.util.function.Predicate;
import com.jozufozu.flywheel.api.FlywheelWorld; import com.jozufozu.flywheel.api.FlywheelWorld;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
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;
@ -16,8 +18,12 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; 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 net.minecraft.world.level.lighting.LevelLightEngine;
import org.jetbrains.annotations.NotNull;
public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWorld { public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWorld {
public Map<BlockPos, BlockState> blocksAdded; public Map<BlockPos, BlockState> blocksAdded;
public Map<BlockPos, BlockEntity> tesAdded; public Map<BlockPos, BlockEntity> tesAdded;
@ -27,12 +33,15 @@ 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();
public PlacementSimulationWorld(Level wrapped) { private final Contraption contraption;
this(wrapped, new WrappedChunkProvider());
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); super(wrapped, chunkProvider);
contraption = c;
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
@ -117,4 +126,24 @@ public class PlacementSimulationWorld extends WrappedWorld implements FlywheelWo
return state; return state;
return Blocks.AIR.defaultBlockState(); 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);
}
} }

View file

@ -7,6 +7,10 @@ import java.util.stream.Stream;
import javax.annotation.Nullable; 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 com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld;
import it.unimi.dsi.fastutil.longs.LongSet; 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.level.material.FluidState;
import net.minecraft.world.ticks.BlackholeTickAccess; import net.minecraft.world.ticks.BlackholeTickAccess;
import net.minecraft.world.ticks.TickContainerAccess; import net.minecraft.world.ticks.TickContainerAccess;
import net.minecraftforge.fml.ModList;
public class WrappedChunk extends ChunkAccess { public class WrappedChunk extends ChunkAccess {
@ -50,11 +55,17 @@ public class WrappedChunk extends ChunkAccess {
this.x = x; this.x = x;
this.z = z; 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); 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 @Override