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 > 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 {
TileEntityInstance super T> 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