-
-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
253 additions
and
20 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/BlockRendererAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package net.irisshaders.iris.compat.sodium.mixin; | ||
|
||
import net.caffeinemc.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(BlockRenderer.class) | ||
public interface BlockRendererAccessor { | ||
@Accessor | ||
ChunkBuildBuffers getBuffers(); | ||
} |
42 changes: 42 additions & 0 deletions
42
...c/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinAbstractBlockRenderContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.irisshaders.iris.compat.sodium.mixin; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer; | ||
import net.caffeinemc.mods.sodium.client.render.frapi.render.AbstractBlockRenderContext; | ||
import net.irisshaders.iris.platform.IrisPlatformHelpers; | ||
import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings; | ||
import net.irisshaders.iris.vertices.BlockSensitiveBufferBuilder; | ||
import net.minecraft.client.resources.model.BakedModel; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.level.BlockAndTintGetter; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(AbstractBlockRenderContext.class) | ||
public class MixinAbstractBlockRenderContext { | ||
@Shadow | ||
protected BlockPos pos; | ||
|
||
@Shadow | ||
protected BlockAndTintGetter level; | ||
|
||
@Inject(method = "bufferDefaultModel", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/services/PlatformModelAccess;getQuads(Lnet/minecraft/world/level/BlockAndTintGetter;Lnet/minecraft/core/BlockPos;Lnet/minecraft/client/resources/model/BakedModel;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/Direction;Lnet/minecraft/util/RandomSource;Lnet/minecraft/client/renderer/RenderType;Lnet/caffeinemc/mods/sodium/client/services/SodiumModelData;)Ljava/util/List;")) | ||
private void checkDirectionNeo(BakedModel model, BlockState state, CallbackInfo ci, @Local Direction cullFace) { | ||
if ((Object) this instanceof BlockRenderer r && WorldRenderingSettings.INSTANCE.getBlockStateIds() != null && cullFace != null) { | ||
BlockState appearance = IrisPlatformHelpers.getInstance().getBlockAppearance(this.level, state, cullFace, this.pos); | ||
((BlockSensitiveBufferBuilder) ((BlockRendererAccessor) r).getBuffers()).overrideBlock(WorldRenderingSettings.INSTANCE.getBlockStateIds().getInt(appearance)); | ||
} | ||
} | ||
|
||
@Inject(method = "bufferDefaultModel", at = @At(value = "TAIL")) | ||
private void checkDirectionNeo(BakedModel model, BlockState state, CallbackInfo ci) { | ||
if ((Object) this instanceof BlockRenderer r && WorldRenderingSettings.INSTANCE.getBlockStateIds() != null) { | ||
((BlockSensitiveBufferBuilder) ((BlockRendererAccessor) r).getBuffers()).restoreBlock(); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...n/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinBakedChunkModelBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package net.irisshaders.iris.compat.sodium.mixin; | ||
|
||
import net.caffeinemc.mods.sodium.client.render.chunk.compile.buffers.BakedChunkModelBuilder; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.vertex.builder.ChunkMeshBufferBuilder; | ||
import net.irisshaders.iris.vertices.BlockSensitiveBufferBuilder; | ||
import net.irisshaders.iris.vertices.sodium.terrain.BlockContextHolder; | ||
import net.irisshaders.iris.vertices.sodium.terrain.VertexEncoderInterface; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(value = BakedChunkModelBuilder.class, remap = false) | ||
public class MixinBakedChunkModelBuilder implements BlockSensitiveBufferBuilder { | ||
@Unique | ||
private final BlockContextHolder contextHolder = new BlockContextHolder(); | ||
|
||
@Inject(method = "<init>", at = @At(value = "TAIL")) | ||
private void setupContextHolder(ChunkMeshBufferBuilder[] vertexBuffers, CallbackInfo ci) { | ||
for (ChunkMeshBufferBuilder vertexBuffer : vertexBuffers) { | ||
((VertexEncoderInterface) vertexBuffer).iris$setContextHolder(contextHolder); | ||
} | ||
} | ||
|
||
@Override | ||
public void beginBlock(int block, byte renderType, byte blockEmission, int localPosX, int localPosY, int localPosZ) { | ||
contextHolder.setBlockData(block, renderType, blockEmission, localPosX, localPosY, localPosZ); | ||
} | ||
|
||
@Override | ||
public void overrideBlock(int block) { | ||
contextHolder.overrideBlock(block); | ||
} | ||
|
||
@Override | ||
public void restoreBlock() { | ||
contextHolder.restoreBlock(); | ||
} | ||
|
||
@Override | ||
public void endBlock() { | ||
contextHolder.setBlockData(0, (byte) 0, (byte) 0, 0, 0, 0); | ||
} | ||
|
||
@Override | ||
public void ignoreMidBlock(boolean b) { | ||
contextHolder.setIgnoreMidBlock(b); | ||
} | ||
} |
50 changes: 30 additions & 20 deletions
50
common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinChunkBuildBuffers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,53 @@ | ||
package net.irisshaders.iris.compat.sodium.mixin; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.compile.ChunkBuildBuffers; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.compile.buffers.BakedChunkModelBuilder; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.terrain.TerrainRenderPass; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.vertex.builder.ChunkMeshBufferBuilder; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.vertex.format.ChunkVertexType; | ||
import net.irisshaders.iris.vertices.BlockSensitiveBufferBuilder; | ||
import net.irisshaders.iris.vertices.sodium.terrain.BlockContextHolder; | ||
import net.irisshaders.iris.vertices.sodium.terrain.VertexEncoderInterface; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
@Mixin(value = ChunkBuildBuffers.class, remap = false) | ||
@Mixin(ChunkBuildBuffers.class) | ||
public class MixinChunkBuildBuffers implements BlockSensitiveBufferBuilder { | ||
@Unique | ||
private final BlockContextHolder contextHolder = new BlockContextHolder(); | ||
|
||
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lit/unimi/dsi/fastutil/objects/Reference2ReferenceOpenHashMap;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;")) | ||
private void setupContextHolder(ChunkVertexType vertexType, CallbackInfo ci, @Local TerrainRenderPass pass, @Local ChunkMeshBufferBuilder[] vertexBuffers) { | ||
for (ChunkMeshBufferBuilder vertexBuffer : vertexBuffers) { | ||
((VertexEncoderInterface) vertexBuffer).iris$setContextHolder(contextHolder); | ||
@Shadow | ||
@Final | ||
private Reference2ReferenceOpenHashMap<TerrainRenderPass, BakedChunkModelBuilder> builders; | ||
|
||
@Override | ||
public void beginBlock(int block, byte renderType, byte blockEmission, int localPosX, int localPosY, int localPosZ) { | ||
for (BakedChunkModelBuilder value : builders.values()) { | ||
((BlockSensitiveBufferBuilder) value).beginBlock(block, renderType, blockEmission, localPosX, localPosY, localPosZ); | ||
} | ||
} | ||
|
||
@Override | ||
public void beginBlock(int block, byte renderType, byte blockEmission, int localPosX, int localPosY, int localPosZ) { | ||
contextHolder.setBlockData(block, renderType, blockEmission, localPosX, localPosY, localPosZ); | ||
public void overrideBlock(int block) { | ||
for (BakedChunkModelBuilder value : builders.values()) { | ||
((BlockSensitiveBufferBuilder) value).overrideBlock(block); | ||
} | ||
} | ||
|
||
@Override | ||
public void restoreBlock() { | ||
for (BakedChunkModelBuilder value : builders.values()) { | ||
((BlockSensitiveBufferBuilder) value).restoreBlock(); | ||
} | ||
} | ||
|
||
@Override | ||
public void endBlock() { | ||
contextHolder.setBlockData(0, (byte) 0, (byte) 0, 0, 0, 0); | ||
for (BakedChunkModelBuilder value : builders.values()) { | ||
((BlockSensitiveBufferBuilder) value).endBlock(); | ||
} | ||
} | ||
|
||
@Override | ||
public void ignoreMidBlock(boolean b) { | ||
contextHolder.setIgnoreMidBlock(b); | ||
for (BakedChunkModelBuilder value : builders.values()) { | ||
((BlockSensitiveBufferBuilder) value).ignoreMidBlock(b); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
common/src/main/java/net/irisshaders/iris/compat/sodium/mixin/MixinChunkVertexConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package net.irisshaders.iris.compat.sodium.mixin; | ||
|
||
import net.caffeinemc.mods.sodium.client.render.chunk.compile.buffers.ChunkModelBuilder; | ||
import net.caffeinemc.mods.sodium.client.render.chunk.compile.buffers.ChunkVertexConsumer; | ||
import net.irisshaders.iris.vertices.BlockSensitiveBufferBuilder; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
@Mixin(value = ChunkVertexConsumer.class, remap = false) | ||
public class MixinChunkVertexConsumer implements BlockSensitiveBufferBuilder { | ||
@Shadow | ||
@Final | ||
private ChunkModelBuilder modelBuilder; | ||
|
||
@Override | ||
public void beginBlock(int block, byte renderType, byte blockEmission, int localPosX, int localPosY, int localPosZ) { | ||
((BlockSensitiveBufferBuilder) modelBuilder).beginBlock(block, renderType, blockEmission, localPosX, localPosY, localPosZ); | ||
} | ||
|
||
@Override | ||
public void overrideBlock(int block) { | ||
((BlockSensitiveBufferBuilder) modelBuilder).overrideBlock(block); | ||
} | ||
|
||
@Override | ||
public void restoreBlock() { | ||
((BlockSensitiveBufferBuilder) modelBuilder).restoreBlock(); | ||
} | ||
|
||
@Override | ||
public void endBlock() { | ||
((BlockSensitiveBufferBuilder) modelBuilder).endBlock(); | ||
} | ||
|
||
@Override | ||
public void ignoreMidBlock(boolean b) { | ||
((BlockSensitiveBufferBuilder) modelBuilder).ignoreMidBlock(b); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
neoforge/src/main/java/net/irisshaders/iris/mixin/forge/MixinGameClientEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.irisshaders.iris.mixin.forge; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.mojang.blaze3d.vertex.VertexConsumer; | ||
import net.irisshaders.iris.shaderpack.materialmap.WorldRenderingSettings; | ||
import net.irisshaders.iris.vertices.BlockSensitiveBufferBuilder; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.neoforged.neoforge.client.event.AddSectionGeometryEvent; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Pseudo; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Pseudo | ||
@Mixin(targets = "com/portingdeadmods/cable_facades/events/GameClientEvents$2", remap = true) | ||
public class MixinGameClientEvents { | ||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;renderBatched(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;ZLnet/minecraft/util/RandomSource;Lnet/neoforged/neoforge/client/model/data/ModelData;Lnet/minecraft/client/renderer/RenderType;)V")) | ||
private void iris$setId(AddSectionGeometryEvent.SectionRenderingContext sectionRenderingContext, CallbackInfo ci, @Local BlockState state, @Local VertexConsumer buffer, @Local BlockPos pos) { | ||
if (WorldRenderingSettings.INSTANCE.getBlockStateIds() == null) return; | ||
((BlockSensitiveBufferBuilder) buffer).beginBlock(WorldRenderingSettings.INSTANCE.getBlockStateIds().getInt(state), (byte) 0, (byte) state.getLightEmission(), pos.getX(), pos.getY(), pos.getZ()); | ||
} | ||
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockRenderDispatcher;renderBatched(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;ZLnet/minecraft/util/RandomSource;Lnet/neoforged/neoforge/client/model/data/ModelData;Lnet/minecraft/client/renderer/RenderType;)V", shift = At.Shift.AFTER)) | ||
private void iris$removeId(AddSectionGeometryEvent.SectionRenderingContext sectionRenderingContext, CallbackInfo ci, @Local BlockState state, @Local VertexConsumer buffer, @Local BlockPos pos) { | ||
if (WorldRenderingSettings.INSTANCE.getBlockStateIds() == null) return; | ||
((BlockSensitiveBufferBuilder) buffer).endBlock(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters