Skip to content

Commit

Permalink
1.20.5 -> 1.21-pre2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Jun 4, 2024
1 parent cd90a10 commit 154ae67
Show file tree
Hide file tree
Showing 24 changed files with 62 additions and 56 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ org.gradle.daemon=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.20.5
yarn_mappings=1.20.5+build.1
loader_version=0.15.7
fabric_version=0.97.5+1.20.5
minecraft_version=1.21-pre2
yarn_mappings=1.21-pre2+build.2
loader_version=0.15.11
fabric_version=0.99.4+1.21

# Mod Properties
group=com.minelittlepony
Expand All @@ -15,9 +15,9 @@ org.gradle.daemon=false
description=Json-based entity models. Mson.

# Publishing
minecraft_version_range=>=1.20.5
minecraft_version_range=>=1.21-pre2
modrinth_loader_type=fabric
modrinth_project_id=

# Dependencies
modmenu_version=10.0.0-beta.1
modmenu_version=11.0.0-beta.1
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
* Renderers added here will be inserted after Mson models are refreshed.
*/
public interface EntityRendererRegistry {
/**
* Adds a custom player renderer.
*
* @deprecated Use the more flexible predicate version instead.
*/
@Deprecated
default <T extends PlayerEntityRenderer> void registerPlayerRenderer(String skinType, Function<EntityRendererFactory.Context, T> constructor) {
registerPlayerRenderer(new Identifier(skinType), player -> player.getSkinTextures().model().getName().equalsIgnoreCase(skinType), constructor);
}
/**
* Adds a custom player renderer.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.joml.Quaternionf;

import com.minelittlepony.mson.api.model.Face.Axis;
import com.minelittlepony.mson.impl.MsonImpl;

import java.util.Set;
import java.util.function.Function;
Expand All @@ -15,9 +16,9 @@
* A builder for creating box quads.
*/
public interface QuadsBuilder {
static Identifier CONE = new Identifier("mson", "cone");
static Identifier PLANE = new Identifier("mson", "plane");
static Identifier CUBE = new Identifier("mson", "cube");
static Identifier CONE = MsonImpl.id("cone");
static Identifier PLANE = MsonImpl.id("plane");
static Identifier CUBE = MsonImpl.id("cube");

static int[][] FACE_VERTEX_OFFSETS = new int[][] {
{}, //Face.NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.util.Identifier;

import com.minelittlepony.mson.api.export.ModelSerializer;
import com.minelittlepony.mson.impl.MsonImpl;

import java.util.Optional;

Expand All @@ -15,7 +16,7 @@
* @param <Data> The type of data that this format consumes (typically json).
*/
public interface ModelFormat<Data> {
Identifier MSON_V2 = new Identifier("mson", "json");
Identifier MSON_V2 = MsonImpl.id("json");

/**
* Mson *.json files
Expand All @@ -25,7 +26,7 @@ public interface ModelFormat<Data> {
/**
* BlockBench *.bbmodel files
*/
Identifier BBMODEL = new Identifier("blockbench", "bbmodel");
Identifier BBMODEL = Identifier.of("blockbench", "bbmodel");

/**
* The file extension that this format is capable of parsing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public CompletableFuture<FileContent<?>> loadModel(Identifier modelId, @Nullable
return loadedFiles.get(modelId);
}
}
Identifier file = new Identifier(modelId.getNamespace(), "models/entity/" + modelId.getPath());
Identifier file = Identifier.of(modelId.getNamespace(), "models/entity/" + modelId.getPath());

Map<Identifier, Resource> resources = getResourceManager().findResources("models/entity", id -> {
return id.getNamespace().equals(file.getNamespace())
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/minelittlepony/mson/impl/MsonImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public class MsonImpl implements Mson, IdentifiableResourceReloadListener {
public static final Logger LOGGER = LogManager.getLogger("Mson");
public static final MsonImpl INSTANCE = new MsonImpl();

private static final Identifier ID = new Identifier("mson", "models");
private static final Identifier ID = id("models");

public static Identifier id(String name) {
return Identifier.of("mson", name);
}

private final PendingEntityRendererRegistry renderers = new PendingEntityRendererRegistry();

Expand All @@ -71,7 +75,7 @@ public void registerVanillaModels(Map<EntityModelLayer, TexturedModelData> model
synchronized (vanillaModels) {
vanillaModels.clear();
modelParts.forEach((layer, vanilla) -> {
Identifier id = new Identifier(layer.getId().getNamespace(), String.format("mson/%s", layer.getId().getPath()));
Identifier id = Identifier.of(layer.getId().getNamespace(), String.format("mson/%s", layer.getId().getPath()));
((MsonImpl.KeyHolder)vanilla).setKey(registeredModels.computeIfAbsent(id, VanillaKey::new));
vanillaModels.add(id);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public final class PendingEntityRendererRegistry implements EntityRendererRegist
public final PendingRegistrations<
Identifier,
Map.Entry<Predicate<AbstractClientPlayerEntity>, Function<EntityRendererFactory.Context, ? extends PlayerEntityRenderer>>
> player = new PendingRegistrations<>(new Identifier("mson", "renderers/player"), (registry, key, entry) -> {
> player = new PendingRegistrations<>(MsonImpl.id("renderers/player"), (registry, key, entry) -> {
registry.registerPlayerRenderer(key, entry.getKey(), entry.getValue());
});
public final PendingRegistrations<
EntityType<?>,
Function<EntityRendererFactory.Context, ? extends EntityRenderer<?>>
> entity = new PendingRegistrations<>(new Identifier("mson", "renderers/entity"), EntityRendererRegistry::registerEntityRenderer);
> entity = new PendingRegistrations<>(MsonImpl.id("renderers/entity"), EntityRendererRegistry::registerEntityRenderer);
public final PendingRegistrations<
BlockEntityType<?>,
Function<BlockEntityRendererFactory.Context, ? extends BlockEntityRenderer<?>>
> block = new PendingRegistrations<>(new Identifier("mson", "renderers/block"), EntityRendererRegistry::registerBlockRenderer);
> block = new PendingRegistrations<>(MsonImpl.id("renderers/block"), EntityRendererRegistry::registerBlockRenderer);

@Override
public <T extends PlayerEntityRenderer> void registerPlayerRenderer(Identifier skinType, Predicate<AbstractClientPlayerEntity> playerPredicate, Function<Context, T> constructor) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/minelittlepony/mson/impl/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.client.render.entity.model.PlayerEntityModel;
import net.minecraft.util.Identifier;

import com.google.common.base.Predicates;
import com.google.gson.JsonParseException;
import com.minelittlepony.mson.api.ModelKey;
import com.minelittlepony.mson.api.ModelView;
Expand All @@ -27,13 +28,11 @@

final class Test {
static void init() {
var ID = new Identifier("mson_test", "planar_cube");
var ID = Identifier.of("mson_test", "planar_cube");
var RAYMAN = playerRendererFactor(Mson.getInstance().registerModel(ID, MsonPlayer::new));
//var PLANE = playerRendererFactor(Mson.getInstance().registerModel(new Identifier("mson_test", "plane"), MsonPlayer::new));

Mson.getInstance().getEntityRendererRegistry().registerPlayerRenderer(ID, player -> {
return true;
}, RAYMAN);
Mson.getInstance().getEntityRendererRegistry().registerPlayerRenderer(ID, Predicates.alwaysTrue(), RAYMAN);
}

static void exportVanillaModels(ModelLoader modelLoader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public FastModelPart(List<Cuboid> cuboids, Map<String, ModelPart> children, floa
}

@Override
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, float red, float green, float blue, float alpha) {
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, int color) {
computeContents();

if (!visible || empty) {
Expand All @@ -51,10 +51,10 @@ public void render(MatrixStack matrices, VertexConsumer vertices, int light, int
rotate(matrices);
if (!hidden) {
MatrixStack.Entry entry = matrices.peek();
fastRenderCuboids(entry, vertices, light, overlay, red, green, blue, alpha);
fastRenderCuboids(entry, vertices, light, overlay, color);
}
for (ModelPart modelPart : parts) {
modelPart.render(matrices, vertices, light, overlay, red, green, blue, alpha);
modelPart.render(matrices, vertices, light, overlay, color);
}
matrices.pop();
}
Expand Down Expand Up @@ -89,7 +89,7 @@ private void computeContents() {
compiled = true;
}

private void fastRenderCuboids(MatrixStack.Entry entry, VertexConsumer vertexConsumer, int light, int overlay, float red, float green, float blue, float alpha) {
private void fastRenderCuboids(MatrixStack.Entry entry, VertexConsumer vertexConsumer, int light, int overlay, int color) {
Matrix4f positionMatrix = entry.getPositionMatrix();
Matrix3f normalMatrix = entry.getNormalMatrix();
Vector4f position = new Vector4f();
Expand All @@ -103,7 +103,7 @@ private void fastRenderCuboids(MatrixStack.Entry entry, VertexConsumer vertexCon
for (Fragment frag : fragments) {
var pos = frag.pos();
var norm = frag.norm();
vertexConsumer.vertex(pos.x, pos.y, pos.z, red, green, blue, alpha, frag.u(), frag.v(), overlay, light, norm.x, norm.y, norm.z);
vertexConsumer.vertex(pos.x, pos.y, pos.z, color, frag.u(), frag.v(), overlay, light, norm.x, norm.y, norm.z);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.minelittlepony.mson.api.exception.EmptyContextException;
import com.minelittlepony.mson.api.model.Texture;
import com.minelittlepony.mson.impl.ModelContextImpl;
import com.minelittlepony.mson.impl.MsonImpl;

import java.util.HashSet;
import java.util.Map;
Expand All @@ -20,7 +21,7 @@
final class EmptyModelContext implements ModelContextImpl, ModelContext.Locals {

static ModelContextImpl INSTANCE = new EmptyModelContext();
static Identifier ID = new Identifier("mson", "null");
static Identifier ID = MsonImpl.id("null");

private EmptyModelContext() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Optional<ModelSerializer<FileContent<?>>> createSerializer() {

@Override
public Optional<FileContent<JsonElement>> loadModel(Identifier modelId, ModelLoader loader) {
Identifier file = new Identifier(modelId.getNamespace(), "models/" + modelId.getPath() + "." + getFileExtension());
Identifier file = modelId.withPath(p -> p + "." + getFileExtension());
return loader.getResourceManager().getResource(file).flatMap(resource -> {
return loadModel(modelId, file, resource, true, loader);
});
Expand Down Expand Up @@ -96,11 +96,11 @@ public <T> Optional<ModelComponent<T>> loadComponent(String name, JsonElement da
}

JsonObject json = data.getAsJsonObject();
Identifier id = new Identifier(json.get("type").getAsString());
Identifier id = Identifier.of(json.get("type").getAsString());
final String fname = Strings.nullToEmpty(name).trim();

if (id.getNamespace().equalsIgnoreCase("minecraft")) {
id = new Identifier("blockbench", id.getPath());
id = Identifier.of("blockbench", id.getPath());
}

return Optional.ofNullable(componentTypes.get(id)).map(c -> (ModelComponent<T>)c.load(context, fname, json));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* }
*/
public class BbCube implements ModelComponent<Cuboid>, QuadsBuilder {
public static final Identifier ID = new Identifier("blockbench", "cube");
public static final Identifier ID = Identifier.of("blockbench", "cube");

private final boolean boxUv;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* }
*/
public class BbPart implements ModelComponent<ModelPart> {
public static final Identifier ID = new Identifier("blockbench", "part");
public static final Identifier ID = Identifier.of("blockbench", "part");

private final float[] origin = new float[3];
private final float[] rotation = new float[3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public JsonFileContent(ModelLoader loader, ModelFormat<JsonElement> format, Iden
this.format = format;
parent = JsonUtil.accept(json, "parent")
.map(JsonElement::getAsString)
.map(Identifier::new)
.map(Identifier::of)
.map(parentId -> loader.loadModel(parentId, format))
.orElseGet(() -> CompletableFuture.completedFuture(EmptyFileContent.INSTANCE));

Expand Down Expand Up @@ -120,11 +120,11 @@ public Optional<Traversable<String>> getSkeleton() {
public CompletableFuture<FileContent<?>> resolve(JsonElement json) {

if (json.isJsonPrimitive()) {
return loader.loadModel(new Identifier(json.getAsString()), format);
return loader.loadModel(Identifier.of(json.getAsString()), format);
}

Identifier id = getLocals().getModelId();
Identifier autoGen = new Identifier(id.getNamespace(), id.getPath() + "_dynamic");
Identifier autoGen = id.withSuffixedPath("_dynamic");

if (json.getAsJsonObject().has("data")) {
throw new JsonParseException("Dynamic model files should not have a nested data block");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String getFileExtension() {

@Override
public Optional<FileContent<JsonElement>> loadModel(Identifier modelId, ModelLoader loader) {
Identifier file = new Identifier(modelId.getNamespace(), "models/" + modelId.getPath() + "." + getFileExtension());
Identifier file = modelId.withPath(p -> "models/" + p + "." + getFileExtension());
return loader.getResourceManager().getResource(file).flatMap(resource -> {
return loadModel(modelId, file, resource, true, loader);
});
Expand Down Expand Up @@ -101,7 +101,7 @@ public <T> Optional<ModelComponent<T>> loadComponent(String name, JsonElement js

return Optional.ofNullable(componentTypes.get(JsonUtil.accept(o, "type")
.map(JsonElement::getAsString)
.map(Identifier::new)
.map(Identifier::of)
.orElse(defaultAs))
)
.map(c -> (ModelComponent<T>)c.load(context, fname, json));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.minelittlepony.mson.api.model.Texture;
import com.minelittlepony.mson.api.parser.ModelComponent;
import com.minelittlepony.mson.api.parser.locals.Local;
import com.minelittlepony.mson.impl.MsonImpl;
import com.minelittlepony.mson.api.parser.FileContent;
import com.minelittlepony.mson.util.JsonUtil;

Expand All @@ -26,7 +27,7 @@
* @author Sollace
*/
public abstract class AbstractJsonParent implements ModelComponent<ModelPart> {
public static final Identifier ID = new Identifier("mson", "compound");
public static final Identifier ID = MsonImpl.id("compound");
private static final float RADS_DEGS_FACTOR = (float)Math.PI / 180F;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.minelittlepony.mson.api.model.Face.Axis;
import com.minelittlepony.mson.api.parser.ModelComponent;
import com.minelittlepony.mson.api.parser.locals.Local;
import com.minelittlepony.mson.impl.MsonImpl;
import com.minelittlepony.mson.api.parser.FileContent;
import com.minelittlepony.mson.util.JsonUtil;

Expand All @@ -24,7 +25,7 @@
* @author Sollace
*/
public class JsonBox implements ModelComponent<Cuboid> {
public static final Identifier ID = new Identifier("mson", "box");
public static final Identifier ID = MsonImpl.id("box");

/**
* The 3D coordinate of where the box should begin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.minelittlepony.mson.api.export.ModelFileWriter;
import com.minelittlepony.mson.api.model.PartBuilder;
import com.minelittlepony.mson.api.parser.ModelComponent;
import com.minelittlepony.mson.impl.MsonImpl;
import com.minelittlepony.mson.api.parser.FileContent;
import com.minelittlepony.mson.util.JsonUtil;

Expand All @@ -27,7 +28,7 @@
* @author Sollace
*/
public class JsonCompound extends AbstractJsonParent {
public static final Identifier ID = new Identifier("mson", "compound");
public static final Identifier ID = MsonImpl.id("compound");

/**
* The child components of this part.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.minelittlepony.mson.api.model.Face.Axis;
import com.minelittlepony.mson.api.parser.FileContent;
import com.minelittlepony.mson.api.parser.locals.Local;
import com.minelittlepony.mson.impl.MsonImpl;
import com.minelittlepony.mson.api.model.QuadsBuilder;

/**
Expand All @@ -20,7 +21,7 @@
* @author Sollace
*/
public class JsonCone extends JsonBox {
public static final Identifier ID = new Identifier("mson", "cone");
public static final Identifier ID = MsonImpl.id("cone");

/**
* The amount by which the box must taper.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.minelittlepony.mson.api.export.ModelFileWriter;
import com.minelittlepony.mson.api.parser.ModelComponent;
import com.minelittlepony.mson.api.parser.locals.LocalBlock;
import com.minelittlepony.mson.impl.MsonImpl;
import com.minelittlepony.mson.api.parser.FileContent;
import com.minelittlepony.mson.util.JsonUtil;

Expand All @@ -26,7 +27,7 @@
* @author Sollace
*/
public class JsonImport implements ModelComponent<ModelPart> {
public static final Identifier ID = new Identifier("mson", "import");
public static final Identifier ID = MsonImpl.id("import");

private final CompletableFuture<FileContent<?>> file;

Expand Down
Loading

0 comments on commit 154ae67

Please sign in to comment.