From cad71e58431b30e9b41da31ea74d6803fae052a6 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Tue, 23 Feb 2021 16:20:46 -0800 Subject: [PATCH 1/3] Even more compatibility. --- .../foundation/render/backend/Backend.java | 17 ++--- .../render/backend/gl/GlBuffer.java | 5 +- .../render/backend/gl/GlVertexArray.java | 9 +-- ...{GlFunctions.java => GlFeatureCompat.java} | 8 +- .../backend/gl/versioned/RGPixelFormat.java | 75 +++++++++++++++++++ .../backend/instancing/InstancedModel.java | 4 +- .../render/backend/light/LightVolume.java | 25 ++++--- 7 files changed, 110 insertions(+), 33 deletions(-) rename src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/{GlFunctions.java => GlFeatureCompat.java} (93%) create mode 100644 src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/RGPixelFormat.java diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java b/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java index 858d54572..5f53ee500 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/Backend.java @@ -3,15 +3,12 @@ package com.simibubi.create.foundation.render.backend; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.ByteBuffer; import java.nio.FloatBuffer; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import java.util.function.Consumer; import java.util.function.Predicate; -import com.simibubi.create.foundation.render.backend.gl.versioned.GlFunctions; +import com.simibubi.create.foundation.render.backend.gl.versioned.GlFeatureCompat; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.lwjgl.opengl.GL; @@ -23,8 +20,6 @@ import com.simibubi.create.foundation.render.backend.gl.shader.GlProgram; import com.simibubi.create.foundation.render.backend.gl.shader.GlShader; import com.simibubi.create.foundation.render.backend.gl.shader.ProgramSpec; import com.simibubi.create.foundation.render.backend.gl.shader.ShaderType; -import com.simibubi.create.foundation.render.backend.gl.versioned.GlVersioned; -import com.simibubi.create.foundation.render.backend.gl.versioned.MapBuffer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.TextureUtil; @@ -45,7 +40,7 @@ public class Backend { private static boolean enabled; public static GLCapabilities capabilities; - public static GlFunctions functions; + public static GlFeatureCompat compat; public Backend() { throw new IllegalStateException(); @@ -74,9 +69,9 @@ public class Backend { public static boolean canUseInstancing() { return enabled && - functions.vertexArrayObjectsSupported() && - functions.drawInstancedSupported() && - functions.instancedArraysSupported(); + compat.vertexArrayObjectsSupported() && + compat.drawInstancedSupported() && + compat.instancedArraysSupported(); } public static boolean canUseVBOs() { @@ -107,7 +102,7 @@ public class Backend { private static void onResourceManagerReload(IResourceManager manager, Predicate predicate) { if (predicate.test(VanillaResourceType.SHADERS)) { capabilities = GL.createCapabilities(); - functions = new GlFunctions(capabilities); + compat = new GlFeatureCompat(capabilities); OptifineHandler.refresh(); refresh(); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java index 8420dab87..1dbd256e5 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlBuffer.java @@ -4,7 +4,6 @@ import java.nio.ByteBuffer; import java.util.function.Consumer; import com.simibubi.create.foundation.render.backend.Backend; -import com.simibubi.create.foundation.render.backend.gl.versioned.GlFunctions; import org.lwjgl.opengl.GL20; public class GlBuffer extends GlObject { @@ -35,11 +34,11 @@ public class GlBuffer extends GlObject { } public void map(int length, Consumer upload) { - Backend.functions.mapBuffer(bufferType, 0, length, upload); + Backend.compat.mapBuffer(bufferType, 0, length, upload); } public void map(int offset, int length, Consumer upload) { - Backend.functions.mapBuffer(bufferType, offset, length, upload); + Backend.compat.mapBuffer(bufferType, offset, length, upload); } protected void deleteInternal(int handle) { diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java index cf6229f6e..e4854990e 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/GlVertexArray.java @@ -3,19 +3,18 @@ package com.simibubi.create.foundation.render.backend.gl; import java.util.function.Consumer; import com.simibubi.create.foundation.render.backend.Backend; -import org.lwjgl.opengl.GL30; public class GlVertexArray extends GlObject { public GlVertexArray() { - setHandle(Backend.functions.genVertexArrays()); + setHandle(Backend.compat.genVertexArrays()); } public void bind() { - Backend.functions.bindVertexArray(handle()); + Backend.compat.bindVertexArray(handle()); } public void unbind() { - Backend.functions.bindVertexArray(0); + Backend.compat.bindVertexArray(0); } public void with(Consumer action) { @@ -25,6 +24,6 @@ public class GlVertexArray extends GlObject { } protected void deleteInternal(int handle) { - Backend.functions.deleteVertexArrays(handle); + Backend.compat.deleteVertexArrays(handle); } } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlFunctions.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlFeatureCompat.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlFunctions.java rename to src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlFeatureCompat.java index 1345661fc..b2eba08e1 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlFunctions.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/GlFeatureCompat.java @@ -13,19 +13,23 @@ import java.util.function.Consumer; * Each field stores an enum variant that provides access to the * most appropriate version of a feature for the current system. */ -public class GlFunctions { +public class GlFeatureCompat { public final MapBuffer mapBuffer; public final VertexArrayObject vertexArrayObject; public final InstancedArrays instancedArrays; public final DrawInstanced drawInstanced; - public GlFunctions(GLCapabilities caps) { + public final RGPixelFormat pixelFormat; + + public GlFeatureCompat(GLCapabilities caps) { mapBuffer = getLatest(MapBuffer.class, caps); vertexArrayObject = getLatest(VertexArrayObject.class, caps); instancedArrays = getLatest(InstancedArrays.class, caps); drawInstanced = getLatest(DrawInstanced.class, caps); + + pixelFormat = getLatest(RGPixelFormat.class, caps); } public void mapBuffer(int target, int offset, int length, Consumer upload) { diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/RGPixelFormat.java b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/RGPixelFormat.java new file mode 100644 index 000000000..9cf035535 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/render/backend/gl/versioned/RGPixelFormat.java @@ -0,0 +1,75 @@ +package com.simibubi.create.foundation.render.backend.gl.versioned; + +import org.lwjgl.opengl.*; + +public enum RGPixelFormat implements GlVersioned { + GL30_RG { + @Override + public boolean supported(GLCapabilities caps) { + return caps.OpenGL30; + } + + @Override + public int internalFormat() { + return GL30.GL_RG8; + } + + @Override + public int format() { + return GL30.GL_RG; + } + + @Override + public int byteCount() { + return 2; + } + }, + GL11_RGB { + @Override + public boolean supported(GLCapabilities caps) { + return caps.OpenGL11; + } + + @Override + public int internalFormat() { + return GL11.GL_RGB8; + } + + @Override + public int format() { + return GL11.GL_RGB; + } + + @Override + public int byteCount() { + return 3; + } + }, + UNSUPPORTED { + @Override + public boolean supported(GLCapabilities caps) { + return true; + } + + @Override + public int internalFormat() { + throw new UnsupportedOperationException(); + } + + @Override + public int format() { + throw new UnsupportedOperationException(); + } + + @Override + public int byteCount() { + throw new UnsupportedOperationException(); + } + } + + ; + + public abstract int internalFormat(); + public abstract int format(); + public abstract int byteCount(); +} diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java index 3b092c919..5903ae496 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedModel.java @@ -115,7 +115,7 @@ public abstract class InstancedModel extends BufferedMod protected void doRender() { vao.with(vao -> { renderSetup(); - Backend.functions.drawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); + Backend.compat.drawArraysInstanced(GL11.GL_QUADS, 0, vertexCount, glInstanceCount); }); } @@ -162,7 +162,7 @@ public abstract class InstancedModel extends BufferedMod instanceFormat.vertexAttribPointers(staticAttributes); for (int i = 0; i < instanceFormat.getShaderAttributeCount(); i++) { - Backend.functions.vertexAttribDivisor(i + staticAttributes, 1); + Backend.compat.vertexAttribDivisor(i + staticAttributes, 1); } }); diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java index 143964ba5..cada1ecad 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java @@ -2,11 +2,12 @@ package com.simibubi.create.foundation.render.backend.light; import java.nio.ByteBuffer; +import com.simibubi.create.foundation.render.backend.Backend; +import com.simibubi.create.foundation.render.backend.gl.versioned.RGPixelFormat; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL20; -import org.lwjgl.opengl.GL40; import org.lwjgl.system.MemoryUtil; import com.simibubi.create.foundation.render.backend.RenderWork; @@ -28,11 +29,15 @@ public class LightVolume { private final GlTexture glTexture; + private final RGPixelFormat pixelFormat; + public LightVolume(GridAlignedBB sampleVolume) { setSampleVolume(sampleVolume); + pixelFormat = Backend.compat.pixelFormat; + this.glTexture = new GlTexture(GL20.GL_TEXTURE_3D); - this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * 2); // TODO: reduce this to span only sampleVolume + this.lightData = MemoryUtil.memAlloc(this.textureVolume.volume() * pixelFormat.byteCount()); // allocate space for the texture GL20.glActiveTexture(GL20.GL_TEXTURE4); @@ -41,7 +46,7 @@ public class LightVolume { int sizeX = textureVolume.sizeX(); int sizeY = textureVolume.sizeY(); int sizeZ = textureVolume.sizeZ(); - GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, GL40.GL_RG8, sizeX, sizeY, sizeZ, 0, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, 0); + GL12.glTexImage3D(GL12.GL_TEXTURE_3D, 0, pixelFormat.internalFormat(), sizeX, sizeY, sizeZ, 0, pixelFormat.format(), GL20.GL_UNSIGNED_BYTE, 0); glTexture.unbind(); GL20.glActiveTexture(GL20.GL_TEXTURE0); @@ -222,7 +227,7 @@ public class LightVolume { // just in case something goes wrong or we accidentally call this before this volume is properly disposed of. if (lightData == null || removed) return; - GL13.glActiveTexture(GL40.GL_TEXTURE4); + GL13.glActiveTexture(GL20.GL_TEXTURE4); glTexture.bind(); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MIN_FILTER, GL13.GL_LINEAR); GL11.glTexParameteri(GL13.GL_TEXTURE_3D, GL13.GL_TEXTURE_MAG_FILTER, GL13.GL_LINEAR); @@ -245,7 +250,7 @@ public class LightVolume { int sizeY = textureVolume.sizeY(); int sizeZ = textureVolume.sizeZ(); - GL12.glTexSubImage3D(GL12.GL_TEXTURE_3D, 0, 0, 0, 0, sizeX, sizeY, sizeZ, GL40.GL_RG, GL40.GL_UNSIGNED_BYTE, lightData); + GL12.glTexSubImage3D(GL12.GL_TEXTURE_3D, 0, 0, 0, 0, sizeX, sizeY, sizeZ, pixelFormat.format(), GL20.GL_UNSIGNED_BYTE, lightData); GL20.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 4); // 4 is the default bufferDirty = false; @@ -269,7 +274,7 @@ public class LightVolume { byte b = (byte) ((block & 0xF) << 4); byte s = (byte) ((sky & 0xF) << 4); - int i = index(x, y, z); + int i = posToIndex(x, y, z); lightData.put(i, b); lightData.put(i + 1, s); } @@ -277,16 +282,16 @@ public class LightVolume { private void writeBlock(int x, int y, int z, int block) { byte b = (byte) ((block & 0xF) << 4); - lightData.put(index(x, y, z), b); + lightData.put(posToIndex(x, y, z), b); } private void writeSky(int x, int y, int z, int sky) { byte b = (byte) ((sky & 0xF) << 4); - lightData.put(index(x, y, z) + 1, b); + lightData.put(posToIndex(x, y, z) + 1, b); } - private int index(int x, int y, int z) { - return (x + textureVolume.sizeX() * (y + z * textureVolume.sizeY())) * 2; + private int posToIndex(int x, int y, int z) { + return (x + textureVolume.sizeX() * (y + z * textureVolume.sizeY())) * pixelFormat.byteCount(); } } From e62d89b21cd6504faf3868603a181816ed4d7328 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 24 Feb 2021 16:52:49 -0800 Subject: [PATCH 2/3] Everything is lit, hopefully all the time now. --- build.gradle | 4 +- .../contraptions/base/KineticTileEntity.java | 10 ++--- .../structureMovement/Contraption.java | 2 +- .../render/ContraptionRenderDispatcher.java | 6 +++ .../mixin/NetworkLightUpdateMixin.java | 43 +++++++++++++++++++ .../foundation/mixin/RenderHooksMixin.java | 8 ++++ .../instancing/InstancedTileRenderer.java | 18 -------- .../render/backend/light/GridAlignedBB.java | 11 +++++ .../render/backend/light/LightVolume.java | 9 ++++ src/main/resources/create.mixins.json | 3 +- 10 files changed, 85 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/NetworkLightUpdateMixin.java diff --git a/build.gradle b/build.gradle index 7477d5da9..0d4a0c6eb 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ minecraft { workingDirectory project.file('run') // property 'mixin.env.disableRefMap', 'true' arg '-mixin.config=create.mixins.json' -// jvmArgs '-XX:+UnlockCommercialFeatures' + jvmArgs '-XX:+UnlockCommercialFeatures' property 'forge.logging.console.level', 'info' property 'fml.earlyprogresswindow', 'false' mods { @@ -132,7 +132,7 @@ dependencies { //runtimeOnly fg.deobf("vazkii.arl:AutoRegLib:1.4-35.69") //runtimeOnly fg.deobf("vazkii.quark:Quark:r2.0-212.984") - annotationProcessor 'org.spongepowered:mixin:0.8:processor' + //annotationProcessor 'org.spongepowered:mixin:0.8:processor' } jar { diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java index 088ce8618..d0ca45720 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticTileEntity.java @@ -81,6 +81,9 @@ public abstract class KineticTileEntity extends SmartTileEntity } super.initialize(); + + if (world != null && world.isRemote) + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.kineticRenderer.add(this)); } @Override @@ -534,13 +537,6 @@ public abstract class KineticTileEntity extends SmartTileEntity return block.hasIntegratedCogwheel(world, pos, state); } - @Override - public void onLoad() { - super.onLoad(); - if (world != null && world.isRemote) - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.kineticRenderer.add(this)); - } - @Override public void onChunkUnloaded() { if (world != null && world.isRemote) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java index e783d6436..fb5c044d4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/Contraption.java @@ -901,7 +901,7 @@ public abstract class Contraption { world.getWorld() .removeTileEntity(add); int flags = BlockFlags.IS_MOVING | BlockFlags.NO_NEIGHBOR_DROPS | BlockFlags.UPDATE_NEIGHBORS - | BlockFlags.BLOCK_UPDATE; + | BlockFlags.BLOCK_UPDATE | BlockFlags.RERENDER_MAIN_THREAD; if (blockIn instanceof IWaterLoggable && oldState.has(BlockStateProperties.WATERLOGGED) && oldState.get(BlockStateProperties.WATERLOGGED) .booleanValue()) { 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 f26e5174b..b35305eed 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 @@ -64,6 +64,12 @@ public class ContraptionRenderDispatcher { } } + public static void notifyLightPacket(ILightReader world, int chunkX, int chunkZ) { + for (RenderedContraption renderer : renderers.values()) { + renderer.getLighter().lightVolume.notifyLightPacket(world, chunkX, chunkZ); + } + } + public static void renderTick() { firstLayer = true; } diff --git a/src/main/java/com/simibubi/create/foundation/mixin/NetworkLightUpdateMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/NetworkLightUpdateMixin.java new file mode 100644 index 000000000..a40c2c088 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/NetworkLightUpdateMixin.java @@ -0,0 +1,43 @@ +package com.simibubi.create.foundation.mixin; + +import com.simibubi.create.content.contraptions.components.structureMovement.render.ContraptionRenderDispatcher; +import com.simibubi.create.foundation.render.backend.RenderWork; +import com.simibubi.create.foundation.render.backend.light.ILightListener; +import net.minecraft.client.Minecraft; +import net.minecraft.client.network.play.ClientPlayNetHandler; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.network.play.server.SUpdateLightPacket; +import net.minecraft.world.chunk.Chunk; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ClientPlayNetHandler.class) +public class NetworkLightUpdateMixin { + + @Inject(at = @At("TAIL"), method = "handleUpdateLight") + private void onLightPacket(SUpdateLightPacket packet, CallbackInfo ci) { + RenderWork.enqueue(() -> { + ClientWorld world = Minecraft.getInstance().world; + + if (world == null) return; + + int chunkX = packet.getChunkX(); + int chunkZ = packet.getChunkZ(); + + Chunk chunk = world.getChunkProvider().getChunk(chunkX, chunkZ, false); + + if (chunk != null) { + chunk.getTileEntityMap() + .values() + .stream() + .filter(tile -> tile instanceof ILightListener) + .map(tile -> (ILightListener) tile) + .forEach(ILightListener::onChunkLightUpdate); + } + + ContraptionRenderDispatcher.notifyLightPacket(world, chunkX, chunkZ); + }); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java index 27f8173ce..eb02006e8 100644 --- a/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java +++ b/src/main/java/com/simibubi/create/foundation/mixin/RenderHooksMixin.java @@ -1,5 +1,11 @@ package com.simibubi.create.foundation.mixin; +import com.simibubi.create.foundation.render.backend.light.ILightListener; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientChunkProvider; +import net.minecraft.util.math.SectionPos; +import net.minecraft.world.ILightReader; +import net.minecraft.world.chunk.Chunk; import org.lwjgl.opengl.GL20; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -21,6 +27,8 @@ import net.minecraft.client.world.ClientWorld; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import java.util.Map; + @OnlyIn(Dist.CLIENT) @Mixin(WorldRenderer.class) public class RenderHooksMixin { diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java index 4f22c016f..9c3c1ced0 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/instancing/InstancedTileRenderer.java @@ -20,8 +20,6 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; public abstract class InstancedTileRenderer

{ - public static WorldAttached> addedLastTick = new WorldAttached<>(ConcurrentHashMap::new); - protected Map> instances = new HashMap<>(); protected Map, RenderMaterial> materials = new HashMap<>(); @@ -35,23 +33,8 @@ public abstract class InstancedTileRenderer

{ public abstract void registerMaterials(); public void tick() { - ClientWorld world = Minecraft.getInstance().world; - int ticks = AnimationTickHolder.getTicks(); - ConcurrentHashMap map = addedLastTick.get(world); - map - .entrySet() - .stream() - .filter(it -> ticks - it.getValue() > 10) - .map(Map.Entry::getKey) - .forEach(te -> { - map.remove(te); - - onLightUpdate(te); - }); - - // Clean up twice a second. This doesn't have to happen every tick, // but this does need to be run to ensure we don't miss anything. if (ticks % 10 == 0) { @@ -82,7 +65,6 @@ public abstract class InstancedTileRenderer

{ TileEntityInstance renderer = InstancedTileRenderRegistry.instance.create(this, tile); if (renderer != null) { - addedLastTick.get(tile.getWorld()).put(tile, AnimationTickHolder.getTicks()); instances.put(tile, renderer); } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/light/GridAlignedBB.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/GridAlignedBB.java index 707efc0bd..e25fe1924 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/light/GridAlignedBB.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/GridAlignedBB.java @@ -53,6 +53,17 @@ public class GridAlignedBB { pos.getWorldEndZ() + 1); } + public static GridAlignedBB fromChunk(int sectionX, int sectionZ) { + int startX = sectionX << 4; + int startZ = sectionZ << 4; + return new GridAlignedBB(startX, + 0, + startZ, + startX + 16, + 256, + startZ + 16); + } + public static AxisAlignedBB toAABB(GridAlignedBB bb) { return new AxisAlignedBB(bb.minX, bb.minY, bb.minZ, bb.maxX, bb.maxY, bb.maxZ); } diff --git a/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java index cada1ecad..5f9290974 100644 --- a/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java +++ b/src/main/java/com/simibubi/create/foundation/render/backend/light/LightVolume.java @@ -133,6 +133,15 @@ public class LightVolume { else if (type == LightType.SKY) copySky(world, changedVolume); } + public void notifyLightPacket(ILightReader world, int chunkX, int chunkZ) { + GridAlignedBB changedVolume = GridAlignedBB.fromChunk(chunkX, chunkZ); + if (!changedVolume.intersects(sampleVolume)) + return; + changedVolume.intersectAssign(sampleVolume); // compute the region contained by us that has dirty lighting data. + + copyLight(world, changedVolume); + } + /** * Completely (re)populate this volume with block and sky lighting data. * This is expensive and should be avoided. diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index e9d682678..6956226de 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -9,7 +9,8 @@ "CancelTileEntityRenderMixin", "LightUpdateMixin", "RenderHooksMixin", - "FogColorTrackerMixin" + "FogColorTrackerMixin", + "NetworkLightUpdateMixin" ], "injectors": { "defaultRequire": 1 From 36e81857a338b62cb68e3cd3a9cdfe2d9064b304 Mon Sep 17 00:00:00 2001 From: JozsefA Date: Wed, 24 Feb 2021 16:57:26 -0800 Subject: [PATCH 3/3] Unmeddle the build script, but profiling is good. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0d4a0c6eb..0bd3d4bb2 100644 --- a/build.gradle +++ b/build.gradle @@ -132,7 +132,7 @@ dependencies { //runtimeOnly fg.deobf("vazkii.arl:AutoRegLib:1.4-35.69") //runtimeOnly fg.deobf("vazkii.quark:Quark:r2.0-212.984") - //annotationProcessor 'org.spongepowered:mixin:0.8:processor' + annotationProcessor 'org.spongepowered:mixin:0.8:processor' } jar {