Don't crash with starlight

This commit is contained in:
JozsefA 2021-04-05 23:23:35 -07:00
parent 3b05e06d35
commit 4ae1ce3dbe
9 changed files with 184 additions and 11 deletions

View file

@ -39,7 +39,8 @@ minecraft {
workingDirectory project.file('run') workingDirectory project.file('run')
// property 'mixin.env.disableRefMap', 'true' // property 'mixin.env.disableRefMap', 'true'
arg '-mixin.config=create.mixins.json' arg '-mixin.config=create.mixins.json'
jvmArgs '-XX:+UnlockCommercialFeatures' //jvmArgs '-XX:+UnlockCommercialFeatures'
jvmArgs '-Dmixin.env.disableRefMap=true'
property 'forge.logging.console.level', 'info' property 'forge.logging.console.level', 'info'
property 'fml.earlyprogresswindow', 'false' property 'fml.earlyprogresswindow', 'false'
mods { mods {
@ -109,6 +110,10 @@ repositories {
maven { maven {
url = "https://www.cursemaven.com" url = "https://www.cursemaven.com"
} }
flatDir {
dirs 'deps'
}
} }
configurations { configurations {
@ -135,6 +140,9 @@ dependencies {
// runtimeOnly fg.deobf("slimeknights.mantle:Mantle:1.16.3-1.6.40") // runtimeOnly fg.deobf("slimeknights.mantle:Mantle:1.16.3-1.6.40")
// runtimeOnly fg.deobf("slimeknights.tconstruct:TConstruct:1.16.3-3.0.1.24") // runtimeOnly fg.deobf("slimeknights.tconstruct:TConstruct:1.16.3-3.0.1.24")
compileOnly fg.deobf("local:starlight-1.0.0-RC1")
//runtimeOnly fg.deobf("local:starlight-1.0.0-RC1")
annotationProcessor 'org.spongepowered:mixin:0.8:processor' annotationProcessor 'org.spongepowered:mixin:0.8:processor'
} }

BIN
deps/starlight-1.0.0-RC1.jar vendored Normal file

Binary file not shown.

View file

@ -16,6 +16,7 @@ import com.simibubi.create.foundation.render.backend.instancing.IInstanceRendere
import com.simibubi.create.foundation.render.backend.light.GridAlignedBB; import com.simibubi.create.foundation.render.backend.light.GridAlignedBB;
import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.AnimationTickHolder;
import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld;
import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorldStarlight;
import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -33,12 +34,7 @@ import net.minecraft.world.gen.feature.template.Template;
import net.minecraft.world.lighting.WorldLightManager; import net.minecraft.world.lighting.WorldLightManager;
import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.ForgeHooksClient;
import net.minecraftforge.client.model.data.EmptyModelData; import net.minecraftforge.client.model.data.EmptyModelData;
import org.lwjgl.opengl.GL11; import net.minecraftforge.fml.ModList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
public class RenderedContraption { public class RenderedContraption {
private final HashMap<RenderType, ContraptionModel> renderLayers = new HashMap<>(); private final HashMap<RenderType, ContraptionModel> renderLayers = new HashMap<>();
@ -170,6 +166,14 @@ public class RenderedContraption {
} }
private static PlacementSimulationWorld setupRenderWorld(World world, Contraption c) { private static PlacementSimulationWorld setupRenderWorld(World world, Contraption c) {
if (ModList.get().isLoaded("starlight")) {
return PlacementSimulationWorldStarlight.setupRenderWorldStarlight(world, c);
} else {
return setupRenderWorldVanilla(world, c);
}
}
private static PlacementSimulationWorld setupRenderWorldVanilla(World world, Contraption c) {
PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(world); PlacementSimulationWorld renderWorld = new PlacementSimulationWorld(world);
renderWorld.setTileEntities(c.presentTileEntities.values()); renderWorld.setTileEntities(c.presentTileEntities.values());

View file

@ -3,6 +3,8 @@ package com.simibubi.create.content.schematics;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.foundation.utility.worldWrappers.WrappedChunkProvider; import com.simibubi.create.foundation.utility.worldWrappers.WrappedChunkProvider;
import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld; import com.simibubi.create.foundation.utility.worldWrappers.WrappedWorld;
import com.simibubi.create.foundation.utility.worldWrappers.chunk.WrappedChunk;
import net.minecraft.block.AbstractFurnaceBlock; import net.minecraft.block.AbstractFurnaceBlock;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -43,7 +45,7 @@ public class SchematicWorld extends WrappedWorld implements IServerWorld {
} }
public SchematicWorld(BlockPos anchor, World original) { public SchematicWorld(BlockPos anchor, World original) {
super(original, new WrappedChunkProvider()); super(original, new WrappedChunkProvider(WrappedChunk::new));
this.blocks = new HashMap<>(); this.blocks = new HashMap<>();
this.tileEntities = new HashMap<>(); this.tileEntities = new HashMap<>();
this.bounds = new MutableBoundingBox(); this.bounds = new MutableBoundingBox();

View file

@ -6,12 +6,19 @@ import java.util.HashSet;
import java.util.function.Predicate; import java.util.function.Predicate;
import com.simibubi.create.foundation.render.backend.instancing.IFlywheelWorld; import com.simibubi.create.foundation.render.backend.instancing.IFlywheelWorld;
import com.simibubi.create.foundation.utility.worldWrappers.chunk.WrappedChunk;
import ca.spottedleaf.starlight.common.light.VariableBlockLightHandler;
import ca.spottedleaf.starlight.common.light.VariableBlockLightHandlerImpl;
import ca.spottedleaf.starlight.common.world.ExtendedWorld;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.SectionPos; import net.minecraft.util.math.SectionPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.lighting.WorldLightManager; import net.minecraft.world.lighting.WorldLightManager;
public class PlacementSimulationWorld extends WrappedWorld implements IFlywheelWorld { public class PlacementSimulationWorld extends WrappedWorld implements IFlywheelWorld {
@ -24,7 +31,7 @@ public class PlacementSimulationWorld extends WrappedWorld implements IFlywheelW
private final BlockPos.Mutable scratch = new BlockPos.Mutable(); private final BlockPos.Mutable scratch = new BlockPos.Mutable();
public PlacementSimulationWorld(World wrapped) { public PlacementSimulationWorld(World wrapped) {
this(wrapped, new WrappedChunkProvider()); this(wrapped, new WrappedChunkProvider(WrappedChunk::new));
} }
public PlacementSimulationWorld(World wrapped, WrappedChunkProvider chunkProvider) { public PlacementSimulationWorld(World wrapped, WrappedChunkProvider chunkProvider) {

View file

@ -0,0 +1,60 @@
package com.simibubi.create.foundation.utility.worldWrappers;
import ca.spottedleaf.starlight.common.light.VariableBlockLightHandler;
import ca.spottedleaf.starlight.common.light.VariableBlockLightHandlerImpl;
import ca.spottedleaf.starlight.common.world.ExtendedWorld;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.feature.template.Template;
import net.minecraft.world.lighting.WorldLightManager;
import com.simibubi.create.content.contraptions.components.structureMovement.Contraption;
import com.simibubi.create.foundation.utility.worldWrappers.chunk.WrappedChunkStarlight;
public class PlacementSimulationWorldStarlight extends PlacementSimulationWorld implements ExtendedWorld {
VariableBlockLightHandler variableBlockLightHandler = new VariableBlockLightHandlerImpl();
public PlacementSimulationWorldStarlight(World wrapped) {
super(wrapped, new WrappedChunkProvider(WrappedChunkStarlight::new));
}
@Override
public Chunk getChunkAtImmediately(int i, int i1) {
return null;
}
@Override
public IChunk getAnyChunkImmediately(int i, int i1) {
return null;
}
@Override
public VariableBlockLightHandler getCustomLightHandler() {
return variableBlockLightHandler;
}
@Override
public void setCustomLightHandler(VariableBlockLightHandler variableBlockLightHandler) {
this.variableBlockLightHandler = variableBlockLightHandler;
}
public static PlacementSimulationWorld setupRenderWorldStarlight(World world, Contraption c) {
PlacementSimulationWorld renderWorld = new PlacementSimulationWorldStarlight(world);
renderWorld.setTileEntities(c.presentTileEntities.values());
for (Template.BlockInfo info : c.getBlocks()
.values())
renderWorld.setBlockState(info.pos, info.state);
WorldLightManager lighter = renderWorld.lighter;
renderWorld.chunkProvider.getLightSources().forEach((pos) -> lighter.func_215573_a(pos, renderWorld.getLightValue(pos)));
lighter.tick(Integer.MAX_VALUE, true, false);
return renderWorld;
}
}

View file

@ -21,6 +21,12 @@ public class WrappedChunkProvider extends AbstractChunkProvider {
public HashMap<Long, WrappedChunk> chunks; public HashMap<Long, WrappedChunk> chunks;
protected final ChunkFactory chunkFactory;
public WrappedChunkProvider(ChunkFactory chunkFactory) {
this.chunkFactory = chunkFactory;
}
public WrappedChunkProvider setWorld(PlacementSimulationWorld world) { public WrappedChunkProvider setWorld(PlacementSimulationWorld world) {
this.world = world; this.world = world;
this.chunks = new HashMap<>(); this.chunks = new HashMap<>();
@ -58,7 +64,8 @@ public class WrappedChunkProvider extends AbstractChunkProvider {
if (chunks == null) if (chunks == null)
return null; return null;
return chunks.computeIfAbsent(pos, $ -> new WrappedChunk(world, x, z));
return chunks.computeIfAbsent(pos, $ -> chunkFactory.create(world, x, z));
} }
@Override @Override
@ -70,4 +77,8 @@ public class WrappedChunkProvider extends AbstractChunkProvider {
public WorldLightManager getLightManager() { public WorldLightManager getLightManager() {
return world.getLightingProvider(); return world.getLightingProvider();
} }
public interface ChunkFactory {
WrappedChunk create(PlacementSimulationWorld world, int x, int z);
}
} }

View file

@ -9,6 +9,9 @@ import javax.annotation.Nullable;
import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld;
import ca.spottedleaf.starlight.common.chunk.ExtendedChunk;
import ca.spottedleaf.starlight.common.light.SWMRNibbleArray;
import ca.spottedleaf.starlight.common.light.StarLightEngine;
import it.unimi.dsi.fastutil.longs.LongSet; import it.unimi.dsi.fastutil.longs.LongSet;
import it.unimi.dsi.fastutil.shorts.ShortList; import it.unimi.dsi.fastutil.shorts.ShortList;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -120,7 +123,7 @@ public class WrappedChunk implements IChunk {
@Override @Override
public ChunkPos getPos() { public ChunkPos getPos() {
return null; return pos;
} }
@Override @Override
@ -257,4 +260,5 @@ public class WrappedChunk implements IChunk {
return null; return null;
} }
} }

View file

@ -0,0 +1,77 @@
package com.simibubi.create.foundation.utility.worldWrappers.chunk;
import ca.spottedleaf.starlight.common.chunk.ExtendedChunk;
import ca.spottedleaf.starlight.common.light.SWMRNibbleArray;
import ca.spottedleaf.starlight.common.light.StarLightEngine;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.IChunk;
import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld;
public class WrappedChunkStarlight extends WrappedChunk implements ExtendedChunk {
private SWMRNibbleArray[] blockNibbles;
private SWMRNibbleArray[] skyNibbles;
private boolean[] skyEmptinessMap;
private boolean[] blockEmptinessMap;
public WrappedChunkStarlight(PlacementSimulationWorld world, int x, int z) {
super(world, x, z);
this.blockNibbles = StarLightEngine.getFilledEmptyLight(world);
this.skyNibbles = StarLightEngine.getFilledEmptyLight(world);
this.skyEmptinessMap = getEmptySectionsForChunk(this);
this.blockEmptinessMap = getEmptySectionsForChunk(this);
}
@Override
public SWMRNibbleArray[] getBlockNibbles() {
return blockNibbles;
}
@Override
public void setBlockNibbles(SWMRNibbleArray[] swmrNibbleArrays) {
this.blockNibbles = swmrNibbleArrays;
}
@Override
public SWMRNibbleArray[] getSkyNibbles() {
return skyNibbles;
}
@Override
public void setSkyNibbles(SWMRNibbleArray[] swmrNibbleArrays) {
this.skyNibbles = swmrNibbleArrays;
}
@Override
public boolean[] getSkyEmptinessMap() {
return skyEmptinessMap;
}
@Override
public void setSkyEmptinessMap(boolean[] booleans) {
this.skyEmptinessMap = booleans;
}
@Override
public boolean[] getBlockEmptinessMap() {
return blockEmptinessMap;
}
@Override
public void setBlockEmptinessMap(boolean[] booleans) {
this.blockEmptinessMap = booleans;
}
public static boolean[] getEmptySectionsForChunk(IChunk chunk) {
ChunkSection[] sections = chunk.getSections();
boolean[] ret = new boolean[sections.length];
for (int i = 0; i < sections.length; ++i) {
ret[i] = sections[i] == null || sections[i].isEmpty();
}
return ret;
}
}