Skip to content

Commit

Permalink
Compat sodium 0.6
Browse files Browse the repository at this point in the history
Signed-off-by: Hendrix-Shen <[email protected]>
  • Loading branch information
Hendrix-Shen committed Oct 29, 2024
1 parent 17b552c commit c4dc36d
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 16 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ mod.version=0.6

# Required Libraries
# MagicLib
dependencies.magiclib_dependency=0.8.636
dependencies.magiclib_version=0.8.636-beta
dependencies.magiclib_dependency=0.8.638
dependencies.magiclib_version=0.8.638-beta

# Annotation processor
dependencies.lombok_version=1.18.34
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline;

import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;

public class BlockRenderer {
public native void renderModel(BakedModel model, BlockState state, BlockPos pos, BlockPos origin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies;
import top.hendrixshen.magiclib.api.dependency.annotation.Dependency;

@Dependencies(require = @Dependency(value = "sodium", versionPredicates = ">0.4.8 <0.5"))
@Dependencies(require = @Dependency(value = "sodium", versionPredicates = ">=0.4.9- <0.5-"))
@Pseudo
@Mixin(value = BlockRenderer.class, remap = false)
public class MixinBlockRenderer_0_4_9 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import top.hendrixshen.magiclib.libs.com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import top.hendrixshen.magiclib.libs.com.llamalad7.mixinextras.injector.wrapoperation.Operation;

@Dependencies(require = @Dependency(value = "sodium", versionPredicates = "~0.5"))
@Dependencies(require = @Dependency(value = "sodium", versionPredicates = ">=0.5- <0.6-"))
@Pseudo
@Mixin(value = BlockRenderer.class, remap = false)
public class MixinBlockRenderer_0_5 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.plusls.ommc.mixin.feature.blockModelNoOffset.sodium;

import com.plusls.ommc.impl.feature.blockModelNoOffset.BlockModelNoOffsetHelper;
import com.plusls.ommc.impl.feature.worldEaterMineHelper.WorldEaterMineHelper;
import com.plusls.ommc.mixin.accessor.AccessorBlockStateBase;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies;
import top.hendrixshen.magiclib.api.dependency.annotation.Dependency;
import top.hendrixshen.magiclib.libs.com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import top.hendrixshen.magiclib.libs.com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;

@Dependencies(require = @Dependency(value = "sodium", versionPredicates = ">=0.6- <0.7-"))
@Pseudo
@Mixin(value = BlockRenderer.class, remap = false)
public abstract class MixinBlockRenderer_0_6 {
@Dynamic
@WrapOperation(
method = "renderModel",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/block/state/BlockState;hasOffsetFunction()Z",
ordinal = 0,
remap = true
),
remap = false
)
private boolean blockModelNoOffset(BlockState blockState, Operation<Boolean> original) {
if (BlockModelNoOffsetHelper.shouldNoOffset(blockState)) {
return false;
}

return original.call(blockState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public abstract class MixinTerrainRenderContext
@Dynamic
@Inject(
method = {
"tessellateBlock", // For fabric-renderer-indigo 0.5.0 and above
"tesselateBlock" // For fabric-renderer-indigo 0.5.0 below
"tessellateBlock", // For fabric-renderer-indigo 0.5.0 and above
"tesselateBlock" // For fabric-renderer-indigo 0.5.0 below
},
at = @At(value = "INVOKE",
//#if MC > 11903
Expand All @@ -77,9 +77,9 @@ private void emitCustomBlockQuads(BlockState blockState, BlockPos blockPos, Bake
//#endif
//#if MC > 11802
CallbackInfo ci) {
//#else
//$$ CallbackInfoReturnable<Boolean> cir) {
//#endif
//#else
//$$ CallbackInfoReturnable<Boolean> cir) {
//#endif
WorldEaterMineHelper.emitCustomBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import org.spongepowered.asm.mixin.Mixin;
import top.hendrixshen.magiclib.api.preprocess.DummyClass;
import top.hendrixshen.magiclib.api.dependency.annotation.Dependency;
import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies;

@Dependencies(require = @Dependency(value = "sodium", versionPredicates = ">0.4.10 <0.5"))
@Mixin(DummyClass.class)
public class MixinBlockRenderer_0_4_11 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//$$ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
//#endif

@Dependencies(require = @Dependency(value = "sodium", versionPredicates = ">0.4.8 <0.4.11"))
@Dependencies(require = @Dependency(value = "sodium", versionPredicates = ">=0.4.9- <0.4.11-"))
@Mixin(value = BlockRenderer.class, remap = false)
public abstract class MixinBlockRenderer_0_4_9 {
@Shadow(remap = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
require = {
@Dependency(value = "minecraft", versionPredicates = ">1.19.4"),
// TODO: Once sodium 0.5+ backport to MC 1.19.4 and below, we can compat it.
@Dependency(value = "sodium", versionPredicates = "~0.5")
@Dependency(value = "sodium", versionPredicates = ">=0.5- <0.6-")
}
)
@Mixin(value = BlockRenderer.class, remap = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.plusls.ommc.mixin.feature.worldEaterMineHelper.sodium;

import com.plusls.ommc.impl.feature.worldEaterMineHelper.WorldEaterMineHelper;
import com.plusls.ommc.mixin.accessor.AccessorBlockStateBase;
import net.caffeinemc.mods.sodium.client.render.chunk.compile.pipeline.BlockRenderer;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies;
import top.hendrixshen.magiclib.api.dependency.annotation.Dependency;

@Dependencies(require = @Dependency(value = "sodium", versionPredicates = ">=0.6- <0.7-"))
@Pseudo
@Mixin(value = BlockRenderer.class, remap = false)
public abstract class MixinBlockRenderer_0_6 {
@Shadow(remap = false)
public abstract void renderModel(BakedModel model, BlockState state, BlockPos pos, BlockPos origin);

@Unique
private final ThreadLocal<Boolean> ommc$renderTag = ThreadLocal.withInitial(() -> false);

@Dynamic
@Inject(method = "renderModel", at = @At("RETURN"))
private void postRenderModel(BakedModel model, BlockState state, BlockPos pos, BlockPos origin, CallbackInfo ci) {
if (WorldEaterMineHelper.shouldUseCustomModel(state, pos) && !this.ommc$renderTag.get()) {
BakedModel customModel = WorldEaterMineHelper.customModels.get(state.getBlock());

if (customModel != null) {
this.ommc$renderTag.set(true);
int originalLightEmission = state.getLightEmission();
((AccessorBlockStateBase) state).setLightEmission(15);
this.renderModel(customModel, state, pos, origin);
((AccessorBlockStateBase) state).setLightEmission(originalLightEmission);
this.ommc$renderTag.set(false);
}
}
}
}
8 changes: 6 additions & 2 deletions src/main/resources/ommc.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
"feature.blockModelNoOffset.fabric.MixinTerrainRenderContext",
"feature.blockModelNoOffset.sodium.MixinBlockRenderer_0_4_9",
"feature.blockModelNoOffset.sodium.MixinBlockRenderer_0_5",
"feature.blockModelNoOffset.sodium.MixinBlockRenderer_0_6",
"feature.blockModelNoOffset.sodium.MixinBlockRendererLegacy",
"feature.blockModelNoOffset.sodium.MixinTerrainRenderContext",
"feature.disableBlocklistCheck.MixinSocialInteractionsManager",
"feature.disableBreakBlock.MixinClientPlayerInteractionManager",
"feature.disableBreakScaffolding.MixinClientPlayerInteractionManager",
"feature.disableMoveDownInScaffolding.MixinScaffoldingBlock",
"feature.disablePistonPushEntity.MixinPistonBlockEntity",
"generic.dontClearChatHistory.MixinChatHud",
"feature.flatDigger.MixinClientPlayerInteractionManager",
"feature.forceBreakingCooldown.MixinClientPlayerInteractionManager",
"feature.highlightEntity.MixinEntity",
Expand All @@ -47,8 +47,10 @@
"feature.worldEaterMineHelper.sodium.MixinBlockRenderer_0_4_11",
"feature.worldEaterMineHelper.sodium.MixinBlockRenderer_0_4_9",
"feature.worldEaterMineHelper.sodium.MixinBlockRenderer_0_5",
"feature.worldEaterMineHelper.sodium.MixinBlockRenderer_0_6",
"feature.worldEaterMineHelper.sodium.MixinBlockRendererLegacy",
"feature.worldEaterMineHelper.sodium.MixinTerrainRenderContext",
"generic.dontClearChatHistory.MixinChatHud",
"generic.sortInventory.MixinAbstractBannerBlockBannerBlock",
"generic.sortInventory.MixinBedBlock",
"generic.sortInventory.MixinShulkerBoxBlock",
Expand All @@ -58,5 +60,7 @@
],
"injectors": {
"defaultRequire": 1
}
},
"mixins": [
]
}

0 comments on commit c4dc36d

Please sign in to comment.