From 1606188d9ad65c66e9d873497ea3271dbdadaf77 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 9 Aug 2024 00:49:36 +0200 Subject: Add custom block textures --- .../PatchBlockModelInSodiumChunkGenerator.java | 29 +++++++++++++++++ .../custommodels/ReplaceBlockBreakSoundPatch.java | 27 +++++++++++++++ .../custommodels/ReplaceBlockHitSoundPatch.java | 30 +++++++++++++++++ .../ReplaceBlockRenderManagerBlockModel.java | 38 ++++++++++++++++++++++ .../custommodels/ReplaceFallbackBlockModel.java | 21 ++++++++++++ 5 files changed, 145 insertions(+) create mode 100644 src/main/java/moe/nea/firmament/mixins/custommodels/PatchBlockModelInSodiumChunkGenerator.java create mode 100644 src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockBreakSoundPatch.java create mode 100644 src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockHitSoundPatch.java create mode 100644 src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockRenderManagerBlockModel.java create mode 100644 src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceFallbackBlockModel.java (limited to 'src/main/java/moe/nea/firmament/mixins/custommodels') diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/PatchBlockModelInSodiumChunkGenerator.java b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchBlockModelInSodiumChunkGenerator.java new file mode 100644 index 0000000..90f20bc --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/PatchBlockModelInSodiumChunkGenerator.java @@ -0,0 +1,29 @@ +package moe.nea.firmament.mixins.custommodels; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import me.jellysquid.mods.sodium.client.render.chunk.compile.tasks.ChunkBuilderMeshingTask; +import moe.nea.firmament.features.texturepack.CustomBlockTextures; +import net.minecraft.block.BlockState; +import net.minecraft.client.render.block.BlockModels; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.util.math.BlockPos; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(ChunkBuilderMeshingTask.class) +public class PatchBlockModelInSodiumChunkGenerator { + @WrapOperation( + method = "execute(Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildContext;Lme/jellysquid/mods/sodium/client/util/task/CancellationToken;)Lme/jellysquid/mods/sodium/client/render/chunk/compile/ChunkBuildOutput;", + at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/block/BlockModels;getModel(Lnet/minecraft/block/BlockState;)Lnet/minecraft/client/render/model/BakedModel;")) + private BakedModel replaceBlockModel(BlockModels instance, BlockState state, Operation original, + @Local(name = "blockPos") BlockPos.Mutable pos) { + var replacement = CustomBlockTextures.getReplacementModel(state, pos); + if (replacement != null) return replacement; + CustomBlockTextures.enterFallbackCall(); + var fallback = original.call(instance, state); + CustomBlockTextures.exitFallbackCall(); + return fallback; + } +} diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockBreakSoundPatch.java b/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockBreakSoundPatch.java new file mode 100644 index 0000000..9401889 --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockBreakSoundPatch.java @@ -0,0 +1,27 @@ +package moe.nea.firmament.mixins.custommodels; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import moe.nea.firmament.features.texturepack.CustomBlockTextures; +import net.minecraft.block.BlockState; +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.sound.BlockSoundGroup; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.math.BlockPos; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(WorldRenderer.class) +public class ReplaceBlockBreakSoundPatch { +// Sadly hypixel does not send a world event here and instead plays the sound on the server directly +// @WrapOperation(method = "processWorldEvent", at = @At(value = "INVOKE", target = "Lnet/minecraft/sound/BlockSoundGroup;getBreakSound()Lnet/minecraft/sound/SoundEvent;")) +// private SoundEvent replaceBreakSoundEvent(BlockSoundGroup instance, Operation original, +// @Local(argsOnly = true) BlockPos pos, @Local BlockState blockState) { +// var replacement = CustomBlockTextures.getReplacement(blockState, pos); +// if (replacement != null && replacement.getSound() != null) { +// return SoundEvent.of(replacement.getSound()); +// } +// return original.call(instance); +// } +} diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockHitSoundPatch.java b/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockHitSoundPatch.java new file mode 100644 index 0000000..f9a1d0d --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockHitSoundPatch.java @@ -0,0 +1,30 @@ +package moe.nea.firmament.mixins.custommodels; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import moe.nea.firmament.features.texturepack.CustomBlockTextures; +import net.minecraft.block.BlockState; +import net.minecraft.client.network.ClientPlayerInteractionManager; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.Random; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(ClientPlayerInteractionManager.class) +public class ReplaceBlockHitSoundPatch { + @WrapOperation(method = "updateBlockBreakingProgress", at = @At(value = "NEW", target = "(Lnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FFLnet/minecraft/util/math/random/Random;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/client/sound/PositionedSoundInstance;")) + private PositionedSoundInstance replaceSound( + SoundEvent sound, SoundCategory category, float volume, float pitch, + Random random, BlockPos pos, Operation original, + @Local BlockState blockState) { + var replacement = CustomBlockTextures.getReplacement(blockState, pos); + if (replacement != null && replacement.getSound() != null) { + sound = SoundEvent.of(replacement.getSound()); + } + return original.call(sound, category, volume, pitch, random, pos); + } +} diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockRenderManagerBlockModel.java b/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockRenderManagerBlockModel.java new file mode 100644 index 0000000..711b2af --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockRenderManagerBlockModel.java @@ -0,0 +1,38 @@ +package moe.nea.firmament.mixins.custommodels; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import moe.nea.firmament.features.texturepack.CustomBlockTextures; +import net.minecraft.block.BlockState; +import net.minecraft.client.render.block.BlockModels; +import net.minecraft.client.render.block.BlockRenderManager; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.util.math.BlockPos; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(BlockRenderManager.class) +public class ReplaceBlockRenderManagerBlockModel { + @WrapOperation(method = "renderBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/block/BlockRenderManager;getModel(Lnet/minecraft/block/BlockState;)Lnet/minecraft/client/render/model/BakedModel;")) + private BakedModel replaceModelInRenderBlock( + BlockRenderManager instance, BlockState state, Operation original, @Local(argsOnly = true) BlockPos pos) { + var replacement = CustomBlockTextures.getReplacementModel(state, pos); + if (replacement != null) return replacement; + CustomBlockTextures.enterFallbackCall(); + var fallback = original.call(instance, state); + CustomBlockTextures.exitFallbackCall(); + return fallback; + } + + @WrapOperation(method = "renderDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/block/BlockModels;getModel(Lnet/minecraft/block/BlockState;)Lnet/minecraft/client/render/model/BakedModel;")) + private BakedModel replaceModelInRenderDamage( + BlockModels instance, BlockState state, Operation original, @Local(argsOnly = true) BlockPos pos) { + var replacement = CustomBlockTextures.getReplacementModel(state, pos); + if (replacement != null) return replacement; + CustomBlockTextures.enterFallbackCall(); + var fallback = original.call(instance, state); + CustomBlockTextures.exitFallbackCall(); + return fallback; + } +} diff --git a/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceFallbackBlockModel.java b/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceFallbackBlockModel.java new file mode 100644 index 0000000..53ab74a --- /dev/null +++ b/src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceFallbackBlockModel.java @@ -0,0 +1,21 @@ +package moe.nea.firmament.mixins.custommodels; + +import moe.nea.firmament.features.texturepack.CustomBlockTextures; +import net.minecraft.block.BlockState; +import net.minecraft.client.render.block.BlockModels; +import net.minecraft.client.render.model.BakedModel; +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(BlockModels.class) +public class ReplaceFallbackBlockModel { + // TODO: add check to BlockDustParticle + @Inject(method = "getModel", at = @At("HEAD"), cancellable = true) + private void getModel(BlockState state, CallbackInfoReturnable cir) { + var replacement = CustomBlockTextures.getReplacementModel(state, null); + if (replacement != null) + cir.setReturnValue(replacement); + } +} -- cgit