mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-14 08:23:50 +01:00
Everything is lit, hopefully all the time now.
This commit is contained in:
parent
cad71e5843
commit
e62d89b21c
10 changed files with 85 additions and 29 deletions
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -20,8 +20,6 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
||||
public static WorldAttached<ConcurrentHashMap<TileEntity, Integer>> addedLastTick = new WorldAttached<>(ConcurrentHashMap::new);
|
||||
|
||||
protected Map<TileEntity, TileEntityInstance<?>> instances = new HashMap<>();
|
||||
|
||||
protected Map<MaterialType<?>, RenderMaterial<P, ?>> materials = new HashMap<>();
|
||||
|
@ -35,23 +33,8 @@ public abstract class InstancedTileRenderer<P extends BasicProgram> {
|
|||
public abstract void registerMaterials();
|
||||
|
||||
public void tick() {
|
||||
ClientWorld world = Minecraft.getInstance().world;
|
||||
|
||||
int ticks = AnimationTickHolder.getTicks();
|
||||
|
||||
ConcurrentHashMap<TileEntity, Integer> 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<P extends BasicProgram> {
|
|||
TileEntityInstance<? super T> renderer = InstancedTileRenderRegistry.instance.create(this, tile);
|
||||
|
||||
if (renderer != null) {
|
||||
addedLastTick.get(tile.getWorld()).put(tile, AnimationTickHolder.getTicks());
|
||||
instances.put(tile, renderer);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
"CancelTileEntityRenderMixin",
|
||||
"LightUpdateMixin",
|
||||
"RenderHooksMixin",
|
||||
"FogColorTrackerMixin"
|
||||
"FogColorTrackerMixin",
|
||||
"NetworkLightUpdateMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in a new issue