From 912a827b7c911653ff850a7a57df005a833db408 Mon Sep 17 00:00:00 2001 From: Adrien1106 Date: Fri, 9 Feb 2024 18:47:58 +0100 Subject: [PATCH] slight cleanup --- .../reframedtemplates/Templates.java | 2 +- .../reframedtemplates/model/QuadUvBounds.java | 2 +- .../model/RetexturingWeightedBakedModel.java | 69 ------------------- .../model/UnbakedMeshRetexturedModel.java | 2 - .../model/apperance/Appearance.java | 3 +- .../model/apperance/TemplateAppearance.java | 9 +-- .../apperance/TemplateAppearanceManager.java | 6 +- .../apperance/WeightedComputedAppearance.java | 2 +- 8 files changed, 11 insertions(+), 84 deletions(-) delete mode 100644 src/main/java/fr/adrien1106/reframedtemplates/model/RetexturingWeightedBakedModel.java diff --git a/src/main/java/fr/adrien1106/reframedtemplates/Templates.java b/src/main/java/fr/adrien1106/reframedtemplates/Templates.java index 9f4268b..c8331d8 100644 --- a/src/main/java/fr/adrien1106/reframedtemplates/Templates.java +++ b/src/main/java/fr/adrien1106/reframedtemplates/Templates.java @@ -49,7 +49,7 @@ import java.util.function.BiConsumer; import java.util.stream.Collectors; /** - * TODO handle random textures wip, handle grass side, multiple camos + * TODO handle random textures rotation and mirroring wip, handle grass side, multiple camos */ public class Templates implements ModInitializer { public static final String MODID = "reframedtemplates"; diff --git a/src/main/java/fr/adrien1106/reframedtemplates/model/QuadUvBounds.java b/src/main/java/fr/adrien1106/reframedtemplates/model/QuadUvBounds.java index 473fa91..ef18201 100644 --- a/src/main/java/fr/adrien1106/reframedtemplates/model/QuadUvBounds.java +++ b/src/main/java/fr/adrien1106/reframedtemplates/model/QuadUvBounds.java @@ -21,7 +21,7 @@ record QuadUvBounds(float minU, float maxU, float minV, float maxV) { return sprite.getMinU() <= minU && sprite.getMaxU() >= maxU && sprite.getMinV() <= minV && sprite.getMaxV() >= maxV; } - void normalizeUv(MutableQuadView quad, Sprite sprite) { + void normalizeUv(MutableQuadView quad, Sprite sprite) { // TODO find out for sprites rotations and mirroring float remappedMinU = norm(minU, sprite.getMinU(), sprite.getMaxU()); float remappedMaxU = norm(maxU, sprite.getMinU(), sprite.getMaxU()); float remappedMinV = norm(minV, sprite.getMinV(), sprite.getMaxV()); diff --git a/src/main/java/fr/adrien1106/reframedtemplates/model/RetexturingWeightedBakedModel.java b/src/main/java/fr/adrien1106/reframedtemplates/model/RetexturingWeightedBakedModel.java deleted file mode 100644 index 87449b2..0000000 --- a/src/main/java/fr/adrien1106/reframedtemplates/model/RetexturingWeightedBakedModel.java +++ /dev/null @@ -1,69 +0,0 @@ -package fr.adrien1106.reframedtemplates.model; - -import fr.adrien1106.reframedtemplates.api.TemplatesClientApi; -import fr.adrien1106.reframedtemplates.model.apperance.TemplateAppearanceManager; -import net.fabricmc.fabric.api.renderer.v1.Renderer; -import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; -import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; -import net.fabricmc.fabric.api.renderer.v1.mesh.MeshBuilder; -import net.fabricmc.fabric.api.renderer.v1.mesh.QuadEmitter; -import net.minecraft.block.BlockState; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.BakedQuad; -import net.minecraft.client.render.model.ModelBakeSettings; -import net.minecraft.util.collection.Weighted; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.random.Random; - -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -public class RetexturingWeightedBakedModel extends RetexturingBakedModel { - - final ConcurrentMap>> jsonToMesh = new ConcurrentHashMap<>(); - - public RetexturingWeightedBakedModel(BakedModel baseModel, TemplateAppearanceManager tam, ModelBakeSettings settings, BlockState itemModelState, boolean ao) { - super(baseModel, tam, settings, itemModelState, ao); - } - - @Override - protected Mesh getBaseMesh(BlockState state) { - return null; -// random.setSeed(seed); -// List> models = jsonToMesh.computeIfAbsent(state, this::convertModel); -// return Weighting -// .getAt(models, Math.abs((int)random.nextLong()) % Weighting.getWeightSum(models)) -// .map(Weighted.Present::getData).get(); - } - - private List> convertModel(BlockState state) { - Renderer r = TemplatesClientApi.getInstance().getFabricRenderer(); - MeshBuilder builder = r.meshBuilder(); - QuadEmitter emitter = builder.getEmitter(); - RenderMaterial mat = tam.getCachedMaterial(state, false); - - Random rand = Random.create(42); - - for(Direction cullFace : DIRECTIONS_AND_NULL) { - for(BakedQuad quad : wrapped.getQuads(state, cullFace, rand)) { - emitter.fromVanilla(quad, mat, cullFace); - - QuadUvBounds bounds = QuadUvBounds.read(emitter); -// for(int i = 0; i < specialSprites.length; i++) { -// if(bounds.displaysSprite(specialSprites[i])) { -// bounds.normalizeUv(emitter, specialSprites[i]); -// emitter.tag(i + 1); -// break; -// } -// } - - emitter.emit(); - } - } - -// builder.build(); - return null; - } - -} diff --git a/src/main/java/fr/adrien1106/reframedtemplates/model/UnbakedMeshRetexturedModel.java b/src/main/java/fr/adrien1106/reframedtemplates/model/UnbakedMeshRetexturedModel.java index 247a98e..ad98ed5 100644 --- a/src/main/java/fr/adrien1106/reframedtemplates/model/UnbakedMeshRetexturedModel.java +++ b/src/main/java/fr/adrien1106/reframedtemplates/model/UnbakedMeshRetexturedModel.java @@ -11,12 +11,10 @@ import net.minecraft.client.render.model.UnbakedModel; import net.minecraft.client.texture.Sprite; import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.util.Identifier; -import net.minecraft.util.math.random.Random; import java.util.Collection; import java.util.Collections; import java.util.function.Function; -import java.util.function.Supplier; public class UnbakedMeshRetexturedModel implements UnbakedModel, TemplatesClientApi.TweakableUnbakedModel { public UnbakedMeshRetexturedModel(Identifier parent, Function, Mesh> baseMeshFactory) { diff --git a/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/Appearance.java b/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/Appearance.java index 5a93ea9..4e8f6e6 100644 --- a/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/Appearance.java +++ b/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/Appearance.java @@ -2,5 +2,4 @@ package fr.adrien1106.reframedtemplates.model.apperance; import net.minecraft.client.texture.Sprite; -record Appearance(Sprite[] sprites, int[] flags, byte color_mask) { -} +public record Appearance(Sprite[] sprites, int[] flags, byte color_mask) {} diff --git a/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/TemplateAppearance.java b/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/TemplateAppearance.java index d25aba0..b7d6348 100644 --- a/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/TemplateAppearance.java +++ b/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/TemplateAppearance.java @@ -2,15 +2,12 @@ package fr.adrien1106.reframedtemplates.model.apperance; import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; import net.minecraft.client.texture.Sprite; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import net.minecraft.util.math.random.Random; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public interface TemplateAppearance { @NotNull RenderMaterial getRenderMaterial(boolean ao); - @NotNull Sprite getSprite(Direction dir, @NotNull long seed); - int getBakeFlags(Direction dir, @NotNull long seed); - boolean hasColor(Direction dir, @NotNull long seed); + @NotNull Sprite getSprite(Direction dir, long seed); + int getBakeFlags(Direction dir, long seed); + boolean hasColor(Direction dir, long seed); } diff --git a/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/TemplateAppearanceManager.java b/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/TemplateAppearanceManager.java index 690066e..8883d89 100644 --- a/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/TemplateAppearanceManager.java +++ b/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/TemplateAppearanceManager.java @@ -15,7 +15,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.RenderLayers; import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.BakedQuad; -import net.minecraft.client.render.model.json.ModelTransformation; import net.minecraft.client.texture.Sprite; import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.screen.PlayerScreenHandler; @@ -24,7 +23,10 @@ import net.minecraft.util.collection.Weighted; import net.minecraft.util.math.Direction; import net.minecraft.util.math.random.Random; -import java.util.*; +import java.util.Arrays; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; diff --git a/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/WeightedComputedAppearance.java b/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/WeightedComputedAppearance.java index f8f1f93..52a884b 100644 --- a/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/WeightedComputedAppearance.java +++ b/src/main/java/fr/adrien1106/reframedtemplates/model/apperance/WeightedComputedAppearance.java @@ -36,7 +36,7 @@ public class WeightedComputedAppearance implements TemplateAppearance { public int getAppearanceIndex(long seed) { Random random = Random.create(seed); return Weighting.getAt(appearances, Math.abs((int)random.nextLong()) % total_weight) - .map(appearances::indexOf).get(); + .map(appearances::indexOf).orElse(0); } private Appearance getAppearance(long seed) {