Half-and-half

This commit is contained in:
quat1024 2023-07-03 20:55:10 -04:00
parent 2d319a8e50
commit 80910e38f5
6 changed files with 61 additions and 6 deletions

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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 = "<init>(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);
}
}
}

View File

@ -17,15 +17,14 @@ public abstract class MixinEntity {
@ModifyArg( @ModifyArg(
method = "spawnSprintingParticles", method = "spawnSprintingParticles",
at = @At(value = "INVOKE", target = "Lnet/minecraft/particle/BlockStateParticleEffect;<init>(Lnet/minecraft/particle/ParticleType;Lnet/minecraft/block/BlockState;)V"), at = @At(value = "INVOKE", target = "Lnet/minecraft/particle/BlockStateParticleEffect;<init>(Lnet/minecraft/particle/ParticleType;Lnet/minecraft/block/BlockState;)V")
require = 0
) )
private BlockState templates$spawnSprintingParticles$modifyParticleState(BlockState origState) { private BlockState templates$spawnSprintingParticles$modifyParticleState(BlockState origState) {
World world = ((Entity) (Object) this).getWorld(); World world = ((Entity) (Object) this).getWorld();
if(world.getBlockEntity(getLandingPos()) instanceof ThemeableBlockEntity themeable) { if(world.getBlockEntity(getLandingPos()) instanceof ThemeableBlockEntity themeable) {
BlockState theme = themeable.getThemeState(); BlockState theme = themeable.getThemeState();
if(theme.getBlock() != Blocks.AIR) return theme; if(!theme.isAir()) return theme;
} }
return origState; return origState;

View File

@ -25,15 +25,14 @@ public class MixinLivingEntity {
@ModifyArg( @ModifyArg(
method = "fall", method = "fall",
at = @At(value = "INVOKE", target = "Lnet/minecraft/particle/BlockStateParticleEffect;<init>(Lnet/minecraft/particle/ParticleType;Lnet/minecraft/block/BlockState;)V"), at = @At(value = "INVOKE", target = "Lnet/minecraft/particle/BlockStateParticleEffect;<init>(Lnet/minecraft/particle/ParticleType;Lnet/minecraft/block/BlockState;)V")
require = 0
) )
private BlockState templates$fall$modifyParticleState(BlockState origState) { private BlockState templates$fall$modifyParticleState(BlockState origState) {
World world = ((Entity) (Object) this).getWorld(); World world = ((Entity) (Object) this).getWorld();
if(lastFallCheckPos != null && world.getBlockEntity(lastFallCheckPos) instanceof ThemeableBlockEntity themeable) { if(lastFallCheckPos != null && world.getBlockEntity(lastFallCheckPos) instanceof ThemeableBlockEntity themeable) {
BlockState theme = themeable.getThemeState(); BlockState theme = themeable.getThemeState();
if(theme.getBlock() != Blocks.AIR) return theme; if(!theme.isAir()) return theme;
} }
return origState; return origState;

View File

@ -6,6 +6,11 @@
"particles.MixinEntity", "particles.MixinEntity",
"particles.MixinLivingEntity" "particles.MixinLivingEntity"
], ],
"client": [
"particles.AccessorParticle",
"particles.AccessorSpriteBillboardParticle",
"particles.MixinBlockDustParticle"
],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1
}, },