slight cleanup

This commit is contained in:
Adrien1106 2024-02-09 18:47:58 +01:00
parent 4315314593
commit 912a827b7c
8 changed files with 11 additions and 84 deletions

View File

@ -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";

View File

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

View File

@ -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<BlockState, List<Weighted.Present<Mesh>>> 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<Weighted.Present<Mesh>> 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<Weighted.Present<Mesh>> 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;
}
}

View File

@ -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<Function<SpriteIdentifier, Sprite>, Mesh> baseMeshFactory) {

View File

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

View File

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

View File

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

View File

@ -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) {