From ab27f361345995d93ab109ac9b3ffa128e0a79bf Mon Sep 17 00:00:00 2001 From: quat1024 Date: Sat, 8 Jul 2023 23:59:34 -0400 Subject: [PATCH] Tweak particles --- .../templates/mixin/MinecraftAccessor.java | 11 +++++++++++ .../mixin/particles/AccessorParticle.java | 7 +++++++ .../mixin/particles/MixinBlockDustParticle.java | 13 +++++++++++-- .../templates/model/RetexturingBakedModel.java | 17 ++++++----------- src/main/resources/templates.mixins.json | 1 + 5 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 src/main/java/io/github/cottonmc/templates/mixin/MinecraftAccessor.java diff --git a/src/main/java/io/github/cottonmc/templates/mixin/MinecraftAccessor.java b/src/main/java/io/github/cottonmc/templates/mixin/MinecraftAccessor.java new file mode 100644 index 0000000..09a928f --- /dev/null +++ b/src/main/java/io/github/cottonmc/templates/mixin/MinecraftAccessor.java @@ -0,0 +1,11 @@ +package io.github.cottonmc.templates.mixin; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.color.item.ItemColors; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(MinecraftClient.class) +public interface MinecraftAccessor { + @Accessor("itemColors") ItemColors templates$getItemColors(); +} 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 index 118b551..c9a1597 100644 --- a/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorParticle.java +++ b/src/main/java/io/github/cottonmc/templates/mixin/particles/AccessorParticle.java @@ -8,4 +8,11 @@ import org.spongepowered.asm.mixin.gen.Accessor; @Mixin(Particle.class) public interface AccessorParticle { @Accessor("random") Random templates$getRandom(); + + @Accessor("red") float templates$red(); + @Accessor("red") void templates$setRed(float red); + @Accessor("green") float templates$green(); + @Accessor("green") void templates$setGreen(float green); + @Accessor("blue") float templates$blue(); + @Accessor("blue") void templates$setBlue(float blue); } 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 index 14596fe..d4f23ef 100644 --- a/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinBlockDustParticle.java +++ b/src/main/java/io/github/cottonmc/templates/mixin/particles/MixinBlockDustParticle.java @@ -19,12 +19,21 @@ public class MixinBlockDustParticle { 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()) { + AccessorParticle a = (AccessorParticle) this; + if(a.templates$getRandom().nextBoolean() && clientWorld.getBlockEntity(pos) instanceof ThemeableBlockEntity themeable) { BlockState theme = themeable.getThemeState(); - if(theme.isAir()) return; + if(theme == null || theme.isAir()) return; Sprite replacement = MinecraftClient.getInstance().getBlockRenderManager().getModels().getModelParticleSprite(theme); ((AccessorSpriteBillboardParticle) this).templates$setSprite(replacement); + + //basically just re-implement what the constructor does - since we mixin at tail, this already ran + //some modifyvariable magic on the BlockState wouldn't hurt, i suppose, but, eh + //it'd need to capture method arguments but 99% of block dust particles are not for template blocks + int color = MinecraftClient.getInstance().getBlockColors().getColor(theme, clientWorld, pos, 0); + a.templates$setRed(0.6f * ((color & 0xFF0000) >> 16) / 255f); + a.templates$setGreen(0.6f * ((color & 0x00FF00) >> 8) / 255f); + a.templates$setBlue(0.6f * (color & 0x0000FF) / 255f); } } } diff --git a/src/main/java/io/github/cottonmc/templates/model/RetexturingBakedModel.java b/src/main/java/io/github/cottonmc/templates/model/RetexturingBakedModel.java index 5fcee26..4f36f40 100644 --- a/src/main/java/io/github/cottonmc/templates/model/RetexturingBakedModel.java +++ b/src/main/java/io/github/cottonmc/templates/model/RetexturingBakedModel.java @@ -1,14 +1,13 @@ package io.github.cottonmc.templates.model; -import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; +import io.github.cottonmc.templates.mixin.MinecraftAccessor; import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; import net.minecraft.block.BlockState; -import net.minecraft.client.color.block.BlockColorProvider; -import net.minecraft.client.color.item.ItemColorProvider; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.ModelBakeSettings; import net.minecraft.client.texture.Sprite; @@ -43,13 +42,11 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { protected final BlockState itemModelState; private static record CacheKey(BlockState state, TemplateAppearance appearance) {} - private final ConcurrentMap retexturedMeshes = new ConcurrentHashMap<>(); + private final ConcurrentMap retexturedMeshes = new ConcurrentHashMap<>(); //mutable, append-only cache protected static final Direction[] DIRECTIONS = Direction.values(); protected static final Direction[] DIRECTIONS_AND_NULL = new Direction[DIRECTIONS.length + 1]; - static { - System.arraycopy(DIRECTIONS, 0, DIRECTIONS_AND_NULL, 0, DIRECTIONS.length); - } + static { System.arraycopy(DIRECTIONS, 0, DIRECTIONS_AND_NULL, 0, DIRECTIONS.length); } protected abstract Mesh getBaseMesh(BlockState state); @@ -73,8 +70,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { TemplateAppearance ta = tam.getAppearance(theme); - BlockColorProvider prov = ColorProviderRegistry.BLOCK.get(theme.getBlock()); - int tint = prov == null ? 0xFFFFFFFF : (0xFF000000 | prov.getColor(theme, blockView, pos, 1)); + int tint = 0xFF000000 | MinecraftClient.getInstance().getBlockColors().getColor(theme, blockView, pos, 0); Mesh untintedMesh = getUntintedRetexturedMesh(new CacheKey(state, ta)); //The specific tint might vary a lot; imagine grass color smoothly changing. Trying to bake the tint into @@ -101,8 +97,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { if(!theme.isAir()) { nbtAppearance = tam.getAppearance(theme); - ItemColorProvider prov = ColorProviderRegistry.ITEM.get(theme.getBlock()); - if(prov != null) tint = prov.getColor(new ItemStack(theme.getBlock()), 1); + tint = 0xFF000000 | ((MinecraftAccessor) MinecraftClient.getInstance()).templates$getItemColors().getColor(new ItemStack(theme.getBlock()), 0); } } diff --git a/src/main/resources/templates.mixins.json b/src/main/resources/templates.mixins.json index 3f319f8..5299cec 100644 --- a/src/main/resources/templates.mixins.json +++ b/src/main/resources/templates.mixins.json @@ -3,6 +3,7 @@ "package": "io.github.cottonmc.templates.mixin", "compatibilityLevel": "JAVA_17", "mixins": [ + "MinecraftAccessor", "WallBlockAccessor", "particles.MixinEntity", "particles.MixinLivingEntity"