From 5779aa7bee18b91fe519805a464bcce56a25927b Mon Sep 17 00:00:00 2001 From: Adrien1106 Date: Mon, 26 Feb 2024 16:47:31 +0100 Subject: [PATCH] added support for multilayered textures with different coloration's such as grass_block --- gradle.properties | 2 +- src/main/java/fr/adrien1106/reframed/ReFramed.java | 2 +- .../client/model/RetexturingBakedModel.java | 10 +++++----- .../client/model/apperance/Appearance.java | 2 +- .../client/model/apperance/CamoAppearance.java | 2 +- .../model/apperance/CamoAppearanceManager.java | 14 ++++++++------ .../client/model/apperance/ComputedAppearance.java | 6 ++++-- .../model/apperance/SingleSpriteAppearance.java | 4 ++-- .../client/model/apperance/SpriteProperties.java | 2 +- .../apperance/WeightedComputedAppearance.java | 6 ++++-- 10 files changed, 28 insertions(+), 22 deletions(-) diff --git a/gradle.properties b/gradle.properties index eb6fe2f..42582c6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=1.20.4+build.3 loader_version=0.15.6 # Mod Properties -mod_version = 1.1 +mod_version = 1.2 maven_group = fr.adrien1106 archives_base_name = ReFramed mod_id = reframed diff --git a/src/main/java/fr/adrien1106/reframed/ReFramed.java b/src/main/java/fr/adrien1106/reframed/ReFramed.java index d6c6019..56c8622 100644 --- a/src/main/java/fr/adrien1106/reframed/ReFramed.java +++ b/src/main/java/fr/adrien1106/reframed/ReFramed.java @@ -25,7 +25,7 @@ import java.util.function.BiConsumer; import java.util.stream.Collectors; /** - * TODO handle grass side, multiple camos + * TODO multiple camos */ public class ReFramed implements ModInitializer { public static final String MODID = "reframed"; diff --git a/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java b/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java index 8ab222a..be809a6 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/RetexturingBakedModel.java @@ -145,8 +145,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { protected final CamoAppearance ta; public int transform(QuadEmitter quad, int i) { - int tag = quad.tag(); - if(tag == 0) return 0; //Pass the quad through unmodified. + if(quad.tag() == 0) return 0; //Pass the quad through unmodified. Direction direction = quad.nominalFace(); List sprites = ta.getSprites(direction, seed); @@ -164,6 +163,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { | properties.flags() | (uvlock ? MutableQuadView.BAKE_LOCK_UV : 0) ); + quad.tag(i+1); quad.emit(); return i; } @@ -180,6 +180,7 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { MutableQuadView.BAKE_NORMALIZED | MutableQuadView.BAKE_LOCK_UV ); + quad.tag(i+1); quad.emit(); return i; } @@ -198,10 +199,9 @@ public abstract class RetexturingBakedModel extends ForwardingBakedModel { @Override public boolean transform(MutableQuadView quad) { - int tag = quad.tag(); - if(tag == 0) return true; + if(quad.tag() == 0) return true; - if(ta.hasColor(quad.nominalFace(), seed)) quad.color(tint, tint, tint, tint); + if(ta.hasColor(quad.nominalFace(), seed, quad.tag())) quad.color(tint, tint, tint, tint); return true; } diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/Appearance.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/Appearance.java index c7be281..3b62525 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/Appearance.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/Appearance.java @@ -5,4 +5,4 @@ import net.minecraft.util.math.Direction; import java.util.List; import java.util.Map; -public record Appearance(Map> sprites, byte color_mask) {} +public record Appearance(Map> sprites) {} diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearance.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearance.java index b4fe5d1..ad219e5 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearance.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearance.java @@ -9,5 +9,5 @@ import java.util.List; public interface CamoAppearance { @NotNull RenderMaterial getRenderMaterial(boolean ao); @NotNull List getSprites(Direction dir, long seed); - boolean hasColor(Direction dir, long seed); + boolean hasColor(Direction dir, long seed, int index); } diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearanceManager.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearanceManager.java index e16038f..72d0195 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearanceManager.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/CamoAppearanceManager.java @@ -119,7 +119,6 @@ public class CamoAppearanceManager { Random random = Random.create(); Map> sprites = new EnumMap<>(Direction.class); - byte[] color_mask = {0b000000}; //Read quads off the model by their `cullface` Arrays.stream(Direction.values()).forEach(direction -> { @@ -131,19 +130,22 @@ public class CamoAppearanceManager { sprites.put(direction, new ArrayList<>()); quads.forEach(quad -> { - if(quad.hasColor()) color_mask[0] |= (byte) (1 << direction.ordinal()); - Sprite sprite = quad.getSprite(); if(sprite == null) return; - sprites.compute(direction, (dir, pairs) -> { + sprites.computeIfPresent(direction, (dir, pairs) -> { quad_emitter.fromVanilla(quad, material, direction); - pairs.add(new SpriteProperties(sprite, getBakeFlags(quad_emitter, sprite), QuadPosBounds.read(quad_emitter))); + pairs.add(new SpriteProperties( + sprite, + getBakeFlags(quad_emitter, sprite), + QuadPosBounds.read(quad_emitter), + quad.hasColor()) + ); return pairs; }); }); }); - return new Appearance(sprites, color_mask[0]); + return new Appearance(sprites); } private static int getBakeFlags(QuadEmitter emitter, Sprite sprite) { diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/ComputedAppearance.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/ComputedAppearance.java index f7f4bef..52ccee0 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/ComputedAppearance.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/ComputedAppearance.java @@ -31,8 +31,10 @@ public class ComputedAppearance implements CamoAppearance { } @Override - public boolean hasColor(Direction dir, long seed) { - return (appearance.color_mask() & (1 << dir.ordinal())) != 0; + public boolean hasColor(Direction dir, long seed, int index) { + List properties = getSprites(dir, seed); + if (index != 0) index = properties.size() - index; + return properties.get(index).has_colors(); } @Override diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/SingleSpriteAppearance.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/SingleSpriteAppearance.java index f2fe094..d62e38f 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/SingleSpriteAppearance.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/SingleSpriteAppearance.java @@ -25,11 +25,11 @@ public class SingleSpriteAppearance implements CamoAppearance { @Override public @NotNull List getSprites(Direction dir, long seed) { - return List.of(new SpriteProperties(defaultSprite, 0, null)); + return List.of(new SpriteProperties(defaultSprite, 0, null, false)); } @Override - public boolean hasColor(Direction dir, long seed) { + public boolean hasColor(Direction dir, long seed, int index) { return false; } diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/SpriteProperties.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/SpriteProperties.java index 43c9e5d..a99bbec 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/SpriteProperties.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/SpriteProperties.java @@ -3,5 +3,5 @@ package fr.adrien1106.reframed.client.model.apperance; import fr.adrien1106.reframed.client.model.QuadPosBounds; import net.minecraft.client.texture.Sprite; -public record SpriteProperties(Sprite sprite, int flags, QuadPosBounds bounds) { +public record SpriteProperties(Sprite sprite, int flags, QuadPosBounds bounds, boolean has_colors) { } diff --git a/src/main/java/fr/adrien1106/reframed/client/model/apperance/WeightedComputedAppearance.java b/src/main/java/fr/adrien1106/reframed/client/model/apperance/WeightedComputedAppearance.java index 098b342..4751711 100644 --- a/src/main/java/fr/adrien1106/reframed/client/model/apperance/WeightedComputedAppearance.java +++ b/src/main/java/fr/adrien1106/reframed/client/model/apperance/WeightedComputedAppearance.java @@ -50,8 +50,10 @@ public class WeightedComputedAppearance implements CamoAppearance { @Override - public boolean hasColor(Direction dir, long seed) { - return (getAppearance(seed).color_mask() & (1 << dir.ordinal())) != 0; + public boolean hasColor(Direction dir, long seed, int index) { + List properties = getSprites(dir, seed); + if (index != 0) index = properties.size() - index; + return properties.get(index).has_colors(); } @Override