diff --git a/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorParticle.java b/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorParticle.java new file mode 100644 index 0000000..118b551 --- /dev/null +++ b/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorParticle.java @@ -0,0 +1,11 @@ +package io.github.cottonmc.templates.mixin.particles; + +import net.minecraft.client.particle.Particle; +import net.minecraft.util.math.random.Random; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(Particle.class) +public interface AccessorParticle { + @Accessor("random") Random templates$getRandom(); +} diff --git a/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorSpriteBillboardParticle.java b/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorSpriteBillboardParticle.java new file mode 100644 index 0000000..3060709 --- /dev/null +++ b/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorSpriteBillboardParticle.java @@ -0,0 +1,11 @@ +package io.github.cottonmc.templates.mixin.particles; + +import net.minecraft.client.particle.SpriteBillboardParticle; +import net.minecraft.client.texture.Sprite; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(SpriteBillboardParticle.class) +public interface AccessorSpriteBillboardParticle { + @Invoker("setSprite") void templates$setSprite(Sprite sprite); +} diff --git a/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinBlockDustParticle.java b/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinBlockDustParticle.java new file mode 100644 index 0000000..14596fe --- /dev/null +++ b/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinBlockDustParticle.java @@ -0,0 +1,30 @@ +package io.github.cottonmc.templates.mixin.particles; + +import io.github.cottonmc.templates.api.ThemeableBlockEntity; +import net.minecraft.block.BlockState; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.particle.BlockDustParticle; +import net.minecraft.client.texture.Sprite; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.math.BlockPos; +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.CallbackInfo; + +@Mixin(BlockDustParticle.class) +public class MixinBlockDustParticle { + @Inject( + method = "(Lnet/minecraft/client/world/ClientWorld;DDDDDDLnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;)V", + at = @At("TAIL") + ) + void templates$init$modifyParticleSprite(ClientWorld clientWorld, double d, double e, double f, double g, double h, double i, BlockState state, BlockPos pos, CallbackInfo ci) { + if(clientWorld.getBlockEntity(pos) instanceof ThemeableBlockEntity themeable && ((AccessorParticle) this).templates$getRandom().nextBoolean()) { + BlockState theme = themeable.getThemeState(); + if(theme.isAir()) return; + + Sprite replacement = MinecraftClient.getInstance().getBlockRenderManager().getModels().getModelParticleSprite(theme); + ((AccessorSpriteBillboardParticle) this).templates$setSprite(replacement); + } + } +} diff --git a/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinEntity.java b/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinEntity.java index 7dc6281..314bbe5 100644 --- a/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinEntity.java +++ b/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinEntity.java @@ -17,15 +17,14 @@ public abstract class MixinEntity { @ModifyArg( method = "spawnSprintingParticles", - at = @At(value = "INVOKE", target = "Lnet/minecraft/particle/BlockStateParticleEffect;(Lnet/minecraft/particle/ParticleType;Lnet/minecraft/block/BlockState;)V"), - require = 0 + at = @At(value = "INVOKE", target = "Lnet/minecraft/particle/BlockStateParticleEffect;(Lnet/minecraft/particle/ParticleType;Lnet/minecraft/block/BlockState;)V") ) private BlockState templates$spawnSprintingParticles$modifyParticleState(BlockState origState) { World world = ((Entity) (Object) this).getWorld(); if(world.getBlockEntity(getLandingPos()) instanceof ThemeableBlockEntity themeable) { BlockState theme = themeable.getThemeState(); - if(theme.getBlock() != Blocks.AIR) return theme; + if(!theme.isAir()) return theme; } return origState; diff --git a/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinLivingEntity.java b/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinLivingEntity.java index af98954..7137a6a 100644 --- a/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinLivingEntity.java +++ b/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinLivingEntity.java @@ -25,15 +25,14 @@ public class MixinLivingEntity { @ModifyArg( method = "fall", - at = @At(value = "INVOKE", target = "Lnet/minecraft/particle/BlockStateParticleEffect;(Lnet/minecraft/particle/ParticleType;Lnet/minecraft/block/BlockState;)V"), - require = 0 + at = @At(value = "INVOKE", target = "Lnet/minecraft/particle/BlockStateParticleEffect;(Lnet/minecraft/particle/ParticleType;Lnet/minecraft/block/BlockState;)V") ) private BlockState templates$fall$modifyParticleState(BlockState origState) { World world = ((Entity) (Object) this).getWorld(); if(lastFallCheckPos != null && world.getBlockEntity(lastFallCheckPos) instanceof ThemeableBlockEntity themeable) { BlockState theme = themeable.getThemeState(); - if(theme.getBlock() != Blocks.AIR) return theme; + if(!theme.isAir()) return theme; } return origState; diff --git a/src/main/resources/templates.mixins.json b/src/main/resources/templates.mixins.json index 93ccfd3..e73825d 100644 --- a/src/main/resources/templates.mixins.json +++ b/src/main/resources/templates.mixins.json @@ -6,6 +6,11 @@ "particles.MixinEntity", "particles.MixinLivingEntity" ], + "client": [ + "particles.AccessorParticle", + "particles.AccessorSpriteBillboardParticle", + "particles.MixinBlockDustParticle" + ], "injectors": { "defaultRequire": 1 },