aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/firmament/mixins
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-08-09 00:49:36 +0200
committerLinnea Gräf <nea@nea.moe>2024-08-09 02:20:41 +0200
commit1606188d9ad65c66e9d873497ea3271dbdadaf77 (patch)
treea33ea87c76bd672fe3902455742ba42ae8c91ee1 /src/main/java/moe/nea/firmament/mixins
parent2a023d0a8d4e9af1dff21ea1bc997dfa0c686b14 (diff)
downloadFirmament-1606188d9ad65c66e9d873497ea3271dbdadaf77.tar.gz
Firmament-1606188d9ad65c66e9d873497ea3271dbdadaf77.tar.bz2
Firmament-1606188d9ad65c66e9d873497ea3271dbdadaf77.zip
Add custom block textures
Diffstat (limited to 'src/main/java/moe/nea/firmament/mixins')
-rw-r--r--src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java15
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/PatchBlockModelInSodiumChunkGenerator.java29
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockBreakSoundPatch.java27
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockHitSoundPatch.java30
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceBlockRenderManagerBlockModel.java38
-rw-r--r--src/main/java/moe/nea/firmament/mixins/custommodels/ReplaceFallbackBlockModel.java21
6 files changed, 157 insertions, 3 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java b/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java
index 97f81b0..c1e359d 100644
--- a/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java
+++ b/src/main/java/moe/nea/firmament/mixins/CustomModelBakerPatch.java
@@ -1,5 +1,3 @@
-
-
package moe.nea.firmament.mixins;
import moe.nea.firmament.events.BakeExtraModelsEvent;
@@ -10,6 +8,7 @@ import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
+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;
@@ -29,9 +28,19 @@ public abstract class CustomModelBakerPatch {
@Shadow
abstract UnbakedModel getOrLoadModel(Identifier id);
+ @Shadow
+ protected abstract void add(ModelIdentifier id, UnbakedModel model);
+
+ @Unique
+ private void loadNonItemModel(ModelIdentifier identifier) {
+ UnbakedModel unbakedModel = this.getOrLoadModel(identifier.id());
+ this.add(identifier, unbakedModel);
+ }
+
+
@Inject(method = "bake", at = @At("HEAD"))
public void onBake(ModelLoader.SpriteGetter spliteGetter, CallbackInfo ci) {
- BakeExtraModelsEvent.Companion.publish(new BakeExtraModelsEvent(this::loadItemModel));
+ BakeExtraModelsEvent.Companion.publish(new BakeExtraModelsEvent(this::loadItemModel, this::loadNonItemModel));
modelsToBake.values().forEach(model -> model.setParents(this::getOrLoadModel));
// modelsToBake.keySet().stream()
// .filter(it -> !it.id().getNamespace().equals("minecraft"))
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<BakedModel> 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<SoundEvent> 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<PositionedSoundInstance> 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<BakedModel> 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<BakedModel> 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<BakedModel> cir) {
+ var replacement = CustomBlockTextures.getReplacementModel(state, null);
+ if (replacement != null)
+ cir.setReturnValue(replacement);
+ }
+}