Skip to content

Commit

Permalink
Translate whole project to mojmap
Browse files Browse the repository at this point in the history
  • Loading branch information
KosmX committed Jun 20, 2024
1 parent b871c4e commit c7933d7
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 126 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ subprojects {
// The following line declares the mojmap mappings, you may use other mappings as well
// mappings loom.officialMojangMappings()
// The following line declares the yarn mappings you may select this one as well.
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
// mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" // forge is unusable
mappings loom.officialMojangMappings()
}
}

Expand Down
3 changes: 1 addition & 2 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
architectury {
//common("neoforge", "fabric")
common("fabric")
common("neoforge", "fabric")
}

loom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.github.kosmx.bendylib.impl.DummyCuboid;
import io.github.kosmx.bendylib.impl.accessors.IModelPartAccessor;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.model.geom.ModelPart;

import java.util.*;

Expand All @@ -12,7 +12,7 @@
*/
public final class ModelPartAccessor {

public static Map<String,ModelPart> getChildren(ModelPart modelPart){
public static Map<String, ModelPart> getChildren(ModelPart modelPart){
return ((IModelPartAccessor)modelPart).getChildren();
}

Expand Down Expand Up @@ -41,7 +41,7 @@ public static Optional<MutableCuboid> optionalGetCuboid(ModelPart modelPart, int
return Optional.of((MutableCuboid)getCuboids(modelPart).get(index));
}

public static List<ModelPart.Cuboid> getCuboids(ModelPart modelPart){
public static List<ModelPart.Cube> getCuboids(ModelPart modelPart){
return ((IModelPartAccessor)modelPart).getCuboids();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.kosmx.bendylib;

import io.github.kosmx.bendylib.impl.ICuboid;
import net.minecraft.util.Pair;
import net.minecraft.util.Tuple;
import org.jetbrains.annotations.Nullable;

public interface MutableCuboid {
Expand All @@ -26,7 +26,7 @@ public interface MutableCuboid {
* @return null, if no active
*/
@Nullable
Pair<String, ICuboid> getActiveMutator();
Tuple<String, ICuboid> getActiveMutator();

/**
* Check if mutator with key exists
Expand Down
20 changes: 10 additions & 10 deletions common/src/main/java/io/github/kosmx/bendylib/MutableModelPart.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.kosmx.bendylib;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import io.github.kosmx.bendylib.impl.ICuboid;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.model.geom.ModelPart;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand All @@ -26,23 +26,23 @@ public abstract class MutableModelPart extends ModelPart {

protected final ObjectList<ICuboid> iCuboids = new ObjectArrayList<>();

public MutableModelPart(List<Cuboid> cuboids, Map<String, ModelPart> children) {
public MutableModelPart(List<Cube> cuboids, Map<String, ModelPart> children) {
super(cuboids, children);
}


@Override
public void render(MatrixStack matrices, VertexConsumer vertices, int light, int overlay, int color) {
public void render(PoseStack matrices, VertexConsumer vertices, int light, int overlay, int color) {
super.render(matrices, vertices, light, overlay);
if(!iCuboids.isEmpty()){
matrices.push();
this.rotate(matrices);
this.renderICuboids(matrices.peek(), vertices, light, overlay, color);
matrices.pop();
matrices.pushPose();
this.translateAndRotate(matrices);
this.renderICuboids(matrices.last(), vertices, light, overlay, color);
matrices.popPose();
}
}

protected void renderICuboids(MatrixStack.Entry matrices, VertexConsumer vertexConsumer, int light, int overlay, int color) {
protected void renderICuboids(PoseStack.Pose matrices, VertexConsumer vertexConsumer, int light, int overlay, int color) {
this.iCuboids.forEach((cuboid)-> cuboid.render(matrices, vertexConsumer, light, overlay, color));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import io.github.kosmx.bendylib.impl.IBendable;
import io.github.kosmx.bendylib.impl.IPosWithOrigin;
import io.github.kosmx.bendylib.impl.RememberingPos;
import net.minecraft.client.model.ModelPart;
import net.minecraft.util.math.Direction;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.core.Direction;
import org.joml.Vector3f;
import org.joml.Vector4f;
import org.slf4j.Logger;
Expand All @@ -22,7 +22,7 @@ public static void init() throws ClassNotFoundException, NoClassDefFoundError {
var sourceCuboidOptional = ModelPartAccessor.optionalGetCuboid(modelPart, 0);
if (sourceCuboidOptional.isPresent()
&& sourceCuboidOptional.get().getActiveMutator() != null
&& sourceCuboidOptional.get().getActiveMutator().getRight() instanceof BendableCuboid bendableSource) {
&& sourceCuboidOptional.get().getActiveMutator().getB() instanceof BendableCuboid bendableSource) {


class Bender extends BendyMeshTransformer implements MeshTransformer {
Expand Down Expand Up @@ -51,13 +51,13 @@ public void transform(Vector3f vec3f, Vector4f[] vector4fs) {
}

@Override
public void transform(ModelPart.Cuboid cuboid) {
public void transform(ModelPart.Cube cuboid) {
var sourceCuboid = sourceCuboidOptional.get();
var mutator = sourceCuboidOptional.get().getActiveMutator();

if (cuboid instanceof MutableCuboid mutableCuboid) {
if (!mutableCuboid.hasMutator(mutator.getLeft())) {
mutableCuboid.registerMutator(mutator.getLeft(),
if (!mutableCuboid.hasMutator(mutator.getA())) {
mutableCuboid.registerMutator(mutator.getA(),
data -> new BendableCuboid.Builder().setDirection(getBendDirection()).build(data,
(sides, positions, minX, minY, minZ, maxX, maxY, maxZ, fixX, fixY, fixZ,
direction, basePlane, otherPlane, fullSize) ->
Expand All @@ -80,7 +80,7 @@ public void transform(Vector3f vec3f, Vector4f[] vector4fs) {
}

@Override
public void transform(ModelPart.Cuboid cuboid) {
public void transform(ModelPart.Cube cuboid) {
((MutableCuboid) cuboid).getAndActivateMutator(null);
}
};
Expand All @@ -99,7 +99,7 @@ public static Vector3f calculateNormal(Vector4f[] vertices) {
vecA.add(buf);
vecA.cross(vecB);
//Return the cross product, if it's zero then return anything non-zero to not cause crash...
return vecA.normalize().isFinite() ? vecA : Direction.NORTH.getUnitVector();
return vecA.normalize().isFinite() ? vecA : Direction.NORTH.step();
}

private static class ModifiedBendableCuboid extends BendableCuboid {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.kosmx.bendylib.impl;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import io.github.kosmx.bendylib.ICuboidBuilder;
import io.github.kosmx.bendylib.impl.accessors.DirectionMutator;
import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.*;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.core.Direction;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.joml.Vector4f;
Expand Down Expand Up @@ -181,10 +181,10 @@ public BendableCuboid build(Data data, BuildableBendable builder){
createAndAddQuads(planes, positions, new Vector3f[]{vertex6, vertex2, vertex7}, l, q, n, r, data.textureWidth, data.textureHeight, data.mirror, data);
createAndAddQuads(planes, positions, new Vector3f[]{vertex5, vertex6, vertex8}, n, q, o, r, data.textureWidth, data.textureHeight, data.mirror, data);

Plane aPlane = new Plane(direction.getUnitVector(), vertex7);
Plane bPlane = new Plane(direction.getUnitVector(), vertex1);
Plane aPlane = new Plane(direction.step(), vertex7);
Plane bPlane = new Plane(direction.step(), vertex1);
boolean bl = direction == Direction.UP || direction == Direction.SOUTH || direction == Direction.EAST;
float fullSize = - direction.getUnitVector().dot(vertex1) + direction.getUnitVector().dot(vertex7);
float fullSize = - direction.step().dot(vertex1) + direction.step().dot(vertex7);
float bendX = ((float) data.sizeX + data.x + data.x)/2;
float bendY = ((float) data.sizeY + data.y + data.y)/2;
float bendZ = ((float) data.sizeZ + data.z + data.z)/2;
Expand Down Expand Up @@ -261,7 +261,7 @@ public Matrix4f setRotationDeg(float axis, float val){
}

@Override
public void render(MatrixStack.Entry matrices, VertexConsumer vertexConsumer, int light, int overlay, int color) {
public void render(PoseStack.Pose matrices, VertexConsumer vertexConsumer, int light, int overlay, int color) {
for(Quad quad:sides){
quad.render(matrices, vertexConsumer, light, overlay, color);
}
Expand Down Expand Up @@ -305,16 +305,16 @@ public Quad(RememberingPos[] vertices, float u1, float v1, float u2, float v2, f
}
}
}
public void render(MatrixStack.Entry matrices, VertexConsumer vertexConsumer, int light, int overlay, int color){
public void render(PoseStack.Pose matrices, VertexConsumer vertexConsumer, int light, int overlay, int color){
Vector3f direction = this.getDirection();
direction.mul(matrices.getNormalMatrix());
direction.mul(matrices.normal());

for (int i = 0; i != 4; ++i){
IVertex vertex = this.vertices[i];
Vector3f vertexPos = vertex.getPos();
Vector4f pos = new Vector4f(vertexPos.x/16f, vertexPos.y/16f, vertexPos.z/16f, 1);
pos.mul(matrices.getPositionMatrix());
vertexConsumer.vertex(pos.x, pos.y, pos.z, color, vertex.getU(), vertex.getV(), overlay, light, direction.x, direction.y, direction.z);
pos.mul(matrices.pose());
vertexConsumer.addVertex(pos.x, pos.y, pos.z, color, vertex.getU(), vertex.getV(), overlay, light, direction.x, direction.y, direction.z);
}
}

Expand All @@ -333,18 +333,18 @@ private Vector3f getDirection(){
vecA.add(buf);
vecA.cross(vecB);
// Return the cross product, if it's zero then return anything non-zero to not cause crash...
return vecA.normalize().isFinite() ? vecA : Direction.NORTH.getUnitVector();
return vecA.normalize().isFinite() ? vecA : Direction.NORTH.step();
}

@SuppressWarnings({"ConstantConditions"})
private ModelPart.Quad toModelPart_Quad(){
ModelPart.Quad quad = new ModelPart.Quad(new ModelPart.Vertex[]{
private ModelPart.Polygon toModelPart_Quad(){
ModelPart.Polygon quad = new ModelPart.Polygon(new ModelPart.Vertex[]{
vertices[0].toMojVertex(),
vertices[1].toMojVertex(),
vertices[2].toMojVertex(),
vertices[3].toMojVertex()
}, u1, v1, u2, v2, su, sv, false, Direction.UP);
((DirectionMutator)quad).setDirection(this.getDirection());
((DirectionMutator)quad).bendy_lib$setDirection(this.getDirection());
return quad;
}
}
Expand All @@ -355,8 +355,8 @@ public boolean disableAfterDraw() {
}

@Override
public List<ModelPart.Quad> getQuads() {
List<ModelPart.Quad> sides = new ArrayList<>();
public List<ModelPart.Polygon> getQuads() {
List<ModelPart.Polygon> sides = new ArrayList<>();
for(Quad quad : this.sides){
sides.add(quad.toModelPart_Quad());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.github.kosmx.bendylib.ICuboidBuilder;
import io.github.kosmx.bendylib.MutableCuboid;
import net.minecraft.util.Pair;
import net.minecraft.util.Tuple;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -30,7 +30,7 @@ public boolean unregisterMutator(String name) {

@Nullable
@Override
public Pair<String, ICuboid> getActiveMutator() {
public Tuple<String, ICuboid> getActiveMutator() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.kosmx.bendylib.impl;

import net.minecraft.util.math.*;
import net.minecraft.core.Direction;
import org.joml.*;

import java.lang.Math;
Expand All @@ -20,7 +20,7 @@ public interface IBendable {
*/
default Matrix4f applyBend(float bendAxis, float bendValue, IterableRePos posSupplier){
Vector3f axis = new Vector3f((float) Math.cos(bendAxis), 0, (float) Math.sin(bendAxis));
Matrix3f matrix3f = new Matrix3f().set(getBendDirection().getRotationQuaternion());
Matrix3f matrix3f = new Matrix3f().set(getBendDirection().getRotation());
axis.mul(matrix3f);
Matrix4f transformMatrix = new Matrix4f();

Expand All @@ -34,7 +34,7 @@ default Matrix4f applyBend(float bendAxis, float bendValue, IterableRePos posSup
Plane basePlane = getBasePlane();
Plane otherPlane = getOtherSidePlane();

directionUnit = this.getBendDirection().getUnitVector();
directionUnit = this.getBendDirection().step();
directionUnit.cross(axis);
//parallel to the bend's axis and to the cube's bend direction
Plane bendPlane = new Plane(directionUnit, new Vector3f(this.getBendX(), this.getBendY(), this.getBendZ()));
Expand All @@ -48,7 +48,7 @@ default Matrix4f applyBend(float bendAxis, float bendValue, IterableRePos posSup
float distFromBase = basePlane.distanceTo(newPos);
float distFromOther = otherPlane.distanceTo(newPos);
double s = Math.tan(bendValue/2)*distFromBend;
Vector3f x = getBendDirection().getUnitVector();
Vector3f x = getBendDirection().step();
if(Math.abs(distFromBase) < Math.abs(distFromOther)){
x.mul((float) (-distFromBase/halfSize*s));
newPos.add(x);
Expand Down
21 changes: 11 additions & 10 deletions common/src/main/java/io/github/kosmx/bendylib/impl/ICuboid.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.github.kosmx.bendylib.impl;

import net.minecraft.client.model.ModelPart;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.util.math.MatrixStack;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.model.geom.ModelPart;

import java.util.List;

Expand All @@ -14,15 +15,15 @@
public interface ICuboid {

/**
* See {@link BendableCuboid#render(MatrixStack.Entry, VertexConsumer, float, float, float, float, int, int)} how to do it
* Or you can check the original MC code {@link net.minecraft.client.model.ModelPart#render(MatrixStack, VertexConsumer, int, int)}
* See {@link BendableCuboid#render(PoseStack.Pose, VertexConsumer, int, int, int)} how to do it
* Or you can check the original MC code {@link ModelPart#compile(PoseStack.Pose, VertexConsumer, int, int, int)}
*
* @param matrices Minecraft's Matrix transformation
* @param pose Minecraft's Matrix transformation
* @param vertexConsumer Minecraft Vertex consumer, add vertices to render
* @param light light
* @param overlay overlay
*/
void render(MatrixStack.Entry matrices, VertexConsumer vertexConsumer, int light, int overlay, int color);
void render(PoseStack.Pose pose, VertexConsumer vertexConsumer, int light, int overlay, int color);

/**
* Copy custom state from another cuboid
Expand All @@ -31,19 +32,19 @@ public interface ICuboid {
void copyState(ICuboid other);

/**
* Disable mutation after invoking {@link ICuboid#render(MatrixStack.Entry, VertexConsumer, float, float, float, float, int, int)}
* Disable mutation after invoking {@link ICuboid#render(PoseStack.Pose, VertexConsumer, int, int, int)}
* @return true or false...
*/
default boolean disableAfterDraw(){
return true;
}

/**
* Convert custom Quads to {@link net.minecraft.client.model.ModelPart.Quad}
* Convert custom Quads to {@link net.minecraft.client.model.geom.ModelPart.Polygon}
* Needed for Shader fix
* @return list of converted quads
*/
default List<ModelPart.Quad> getQuads(){
default List<ModelPart.Polygon> getQuads(){
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.kosmx.bendylib.impl;

import net.minecraft.client.model.ModelPart;
import net.minecraft.client.model.geom.ModelPart;
import org.joml.Vector3f;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package io.github.kosmx.bendylib.impl.accessors;

import net.minecraft.client.model.ModelPart;

import net.minecraft.client.model.geom.ModelPart;

/**
* For a shader fix. see {@link io.github.kosmx.bendylib.ModelPartAccessor.Workaround}
*/
public interface CuboidSideAccessor {
ModelPart.Quad[] getSides();
ModelPart.Polygon[] getSides();

void setSides(ModelPart.Quad[] sides);
void setSides(ModelPart.Polygon[] sides);

void resetSides();

Expand Down
Loading

0 comments on commit c7933d7

Please sign in to comment.