Skip to content

Commit

Permalink
Create mixin plugin
Browse files Browse the repository at this point in the history
Fix #9
  • Loading branch information
kalucky0 committed Dec 2, 2024
1 parent f9bb3c1 commit 6fbe45b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
51 changes: 51 additions & 0 deletions src/main/java/net/immortaldevs/colorizer/ColorizerMixinPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package net.immortaldevs.colorizer;

import com.google.common.collect.ImmutableMap;
import net.fabricmc.loader.api.FabricLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;

public final class ColorizerMixinPlugin implements IMixinConfigPlugin {
private static final Supplier<Boolean> TRUE = () -> true;

private static final Map<String, Supplier<Boolean>> CONDITIONS = ImmutableMap.of(
"net.immortaldevs.colorizer.mixin.sodium.WorldSliceMixin", () -> FabricLoader.getInstance().isModLoaded("sodium")
);

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return CONDITIONS.getOrDefault(mixinClassName, TRUE).get();
}

@Override
public void onLoad(String mixinPackage) {
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.immortaldevs.colorizer.mixin.sodium;

import me.jellysquid.mods.sodium.client.world.WorldSlice;
import net.caffeinemc.mods.sodium.client.world.LevelSlice;
import net.immortaldevs.colorizer.BlockColor;
import net.immortaldevs.colorizer.ColorManager;
import net.immortaldevs.colorizer.ColorizerMod;
Expand All @@ -14,15 +14,15 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(value = WorldSlice.class)
@Mixin(value = LevelSlice.class)
public class WorldSliceMixin {

@Inject(method = "getBlockState(III)Lnet/minecraft/block/BlockState;", at = @At(value = "RETURN"),cancellable = true)
@Inject(method = "getBlockState(III)Lnet/minecraft/block/BlockState;", at = @At(value = "RETURN"), cancellable = true)
public void modifyBlockState(int x, int y, int z, CallbackInfoReturnable<BlockState> cir) {
BlockState state = cir.getReturnValue();
if (state != null) {
if (state.getBlock() == Blocks.BARREL) {
BlockColor color = ColorManager.getColor(new BlockPos(x,y,z));
BlockColor color = ColorManager.getColor(new BlockPos(x, y, z));
state = ColorizerMod.BARREL_BLOCK.getDefaultState()
.with(ColorizedBarrelBlock.COLOR, color)
.with(BarrelBlock.FACING, state.get(BarrelBlock.FACING))
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/colorizer.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"minVersion": "0.8",
"package": "net.immortaldevs.colorizer.mixin",
"compatibilityLevel": "JAVA_21",
"plugin": "net.immortaldevs.colorizer.ColorizerMixinPlugin",
"client": [
"BlockMixin",
"ItemMixin",
Expand Down

0 comments on commit 6fbe45b

Please sign in to comment.