Tweak particles
This commit is contained in:
parent
252a01d145
commit
ab27f36134
@ -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();
|
||||||
|
}
|
@ -8,4 +8,11 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
|||||||
@Mixin(Particle.class)
|
@Mixin(Particle.class)
|
||||||
public interface AccessorParticle {
|
public interface AccessorParticle {
|
||||||
@Accessor("random") Random templates$getRandom();
|
@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);
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,21 @@ public class MixinBlockDustParticle {
|
|||||||
at = @At("TAIL")
|
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) {
|
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();
|
BlockState theme = themeable.getThemeState();
|
||||||
if(theme.isAir()) return;
|
if(theme == null || theme.isAir()) return;
|
||||||
|
|
||||||
Sprite replacement = MinecraftClient.getInstance().getBlockRenderManager().getModels().getModelParticleSprite(theme);
|
Sprite replacement = MinecraftClient.getInstance().getBlockRenderManager().getModels().getModelParticleSprite(theme);
|
||||||
((AccessorSpriteBillboardParticle) this).templates$setSprite(replacement);
|
((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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package io.github.cottonmc.templates.model;
|
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.Mesh;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
|
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.model.ForwardingBakedModel;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||||
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView;
|
import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.client.color.block.BlockColorProvider;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.color.item.ItemColorProvider;
|
|
||||||
import net.minecraft.client.render.model.BakedModel;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.render.model.ModelBakeSettings;
|
import net.minecraft.client.render.model.ModelBakeSettings;
|
||||||
import net.minecraft.client.texture.Sprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
@ -43,13 +42,11 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel {
|
|||||||
protected final BlockState itemModelState;
|
protected final BlockState itemModelState;
|
||||||
|
|
||||||
private static record CacheKey(BlockState state, TemplateAppearance appearance) {}
|
private static record CacheKey(BlockState state, TemplateAppearance appearance) {}
|
||||||
private final ConcurrentMap<CacheKey, Mesh> retexturedMeshes = new ConcurrentHashMap<>();
|
private final ConcurrentMap<CacheKey, Mesh> retexturedMeshes = new ConcurrentHashMap<>(); //mutable, append-only cache
|
||||||
|
|
||||||
protected static final Direction[] DIRECTIONS = Direction.values();
|
protected static final Direction[] DIRECTIONS = Direction.values();
|
||||||
protected static final Direction[] DIRECTIONS_AND_NULL = new Direction[DIRECTIONS.length + 1];
|
protected static final Direction[] DIRECTIONS_AND_NULL = new Direction[DIRECTIONS.length + 1];
|
||||||
static {
|
static { System.arraycopy(DIRECTIONS, 0, DIRECTIONS_AND_NULL, 0, DIRECTIONS.length); }
|
||||||
System.arraycopy(DIRECTIONS, 0, DIRECTIONS_AND_NULL, 0, DIRECTIONS.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Mesh getBaseMesh(BlockState state);
|
protected abstract Mesh getBaseMesh(BlockState state);
|
||||||
|
|
||||||
@ -73,8 +70,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel {
|
|||||||
|
|
||||||
TemplateAppearance ta = tam.getAppearance(theme);
|
TemplateAppearance ta = tam.getAppearance(theme);
|
||||||
|
|
||||||
BlockColorProvider prov = ColorProviderRegistry.BLOCK.get(theme.getBlock());
|
int tint = 0xFF000000 | MinecraftClient.getInstance().getBlockColors().getColor(theme, blockView, pos, 0);
|
||||||
int tint = prov == null ? 0xFFFFFFFF : (0xFF000000 | prov.getColor(theme, blockView, pos, 1));
|
|
||||||
Mesh untintedMesh = getUntintedRetexturedMesh(new CacheKey(state, ta));
|
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
|
//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()) {
|
if(!theme.isAir()) {
|
||||||
nbtAppearance = tam.getAppearance(theme);
|
nbtAppearance = tam.getAppearance(theme);
|
||||||
|
|
||||||
ItemColorProvider prov = ColorProviderRegistry.ITEM.get(theme.getBlock());
|
tint = 0xFF000000 | ((MinecraftAccessor) MinecraftClient.getInstance()).templates$getItemColors().getColor(new ItemStack(theme.getBlock()), 0);
|
||||||
if(prov != null) tint = prov.getColor(new ItemStack(theme.getBlock()), 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
"package": "io.github.cottonmc.templates.mixin",
|
"package": "io.github.cottonmc.templates.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"MinecraftAccessor",
|
||||||
"WallBlockAccessor",
|
"WallBlockAccessor",
|
||||||
"particles.MixinEntity",
|
"particles.MixinEntity",
|
||||||
"particles.MixinLivingEntity"
|
"particles.MixinLivingEntity"
|
||||||
|
Loading…
Reference in New Issue
Block a user