diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-05-07 22:41:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-07 22:41:10 +0200 |
commit | 912c8d8a8c9ad412b2f94827e09a9cf262e5b69a (patch) | |
tree | 39abdb48d61f5989210e6e73a1254b36992449f3 /src/main/java/at/hannibal2/skyhanni/mixins | |
parent | 50f3954a3c0e15eb18ae864bbd28e0b645aa9d1b (diff) | |
download | skyhanni-912c8d8a8c9ad412b2f94827e09a9cf262e5b69a.tar.gz skyhanni-912c8d8a8c9ad412b2f94827e09a9cf262e5b69a.tar.bz2 skyhanni-912c8d8a8c9ad412b2f94827e09a9cf262e5b69a.zip |
Feature: Mining Commissions Blocks Color (#1701)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/mixins')
2 files changed, 56 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/BlockRendererDispatcherHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/BlockRendererDispatcherHook.kt new file mode 100644 index 000000000..5903136fa --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/BlockRendererDispatcherHook.kt @@ -0,0 +1,35 @@ +package at.hannibal2.skyhanni.mixins.hooks + +import at.hannibal2.skyhanni.features.mining.MiningCommissionsBlocksColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.block.state.IBlockState +import net.minecraft.client.renderer.BlockRendererDispatcher +import net.minecraft.client.resources.model.IBakedModel +import net.minecraft.util.BlockPos +import net.minecraft.world.IBlockAccess +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable + +fun modifyGetModelFromBlockState( + blockRendererDispatcher: BlockRendererDispatcher, + state: IBlockState?, + worldIn: IBlockAccess, + pos: BlockPos?, + cir: CallbackInfoReturnable<IBakedModel>, +) { + if (state == null || pos == null) return + var returnState: IBlockState = state + + if (!LorenzUtils.inSkyBlock) return + + if (MiningCommissionsBlocksColor.enabled && MiningCommissionsBlocksColor.active) { + for (block in MiningCommissionsBlocksColor.MiningBlock.entries) { + if (block.checkIsland() && block.onCheck(state)) { + returnState = block.onColor(state, block.highlight) + } + } + } + + if (returnState !== state) { + cir.returnValue = blockRendererDispatcher.blockModelShapes.getModelForState(returnState) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinBlockRendererDispatcher.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinBlockRendererDispatcher.java new file mode 100644 index 000000000..6269e17f9 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/renderer/MixinBlockRendererDispatcher.java @@ -0,0 +1,21 @@ +package at.hannibal2.skyhanni.mixins.transformers.renderer; + +import at.hannibal2.skyhanni.mixins.hooks.BlockRendererDispatcherHookKt; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.BlockRendererDispatcher; +import net.minecraft.client.resources.IResourceManagerReloadListener; +import net.minecraft.client.resources.model.IBakedModel; +import net.minecraft.util.BlockPos; +import net.minecraft.world.IBlockAccess; +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.CallbackInfoReturnable; + +@Mixin(BlockRendererDispatcher.class) +public abstract class MixinBlockRendererDispatcher implements IResourceManagerReloadListener { + @Inject(method = "getModelFromBlockState", at = @At("RETURN"), cancellable = true) + private void modifyGetModelFromBlockState(IBlockState state, IBlockAccess worldIn, BlockPos pos, CallbackInfoReturnable<IBakedModel> cir) { + BlockRendererDispatcherHookKt.modifyGetModelFromBlockState((BlockRendererDispatcher) (Object) this, state, worldIn, pos, cir); + } +} |