diff --git a/1.17-update.md b/1.17-update.md deleted file mode 100644 index c83978a..0000000 --- a/1.17-update.md +++ /dev/null @@ -1,16 +0,0 @@ -## About 1.17 rendering changes and this mod - -### model part swapping current state -The current swap mechanic will probably change completely, also it will solve other compatibility issues -At the time, I write this, I don't know how will it work, if you want to use this library, feel free to contact me on Discord. -As soon as I find a good way to inject custom cuboids I'll post the technique. - - -Minecraft 1.17 brought some interesting features, changes in the entity models. -I don't (yet) know what do they want to do, probably a multithreaded rendering, -but it is not implemented yet... - -bendy-lib won't change its model logic now, I want to see what do Mojang going to do. -I'll change some critical things to work with the new logic, but I won't do any thread optimisations... - - diff --git a/common/build.gradle b/common/build.gradle index 6208dc7..45787a9 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -10,16 +10,6 @@ dependencies { // We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies // Do NOT use other classes from fabric loader modImplementation "net.fabricmc:fabric-loader:${rootProject.loader_version}" - - modCompileOnly("maven.modrinth:3dskinlayers:1.5.2-1.19.3-fabric") //TODO -} - -sourceSets { - main { - java { - //exclude "io/github/kosmx/bendylib/compat/tr7zw" - } - } } publishing { diff --git a/common/src/main/java/io/github/kosmx/bendylib/ICuboidBuilder.java b/common/src/main/java/io/github/kosmx/bendylib/ICuboidBuilder.java index 665c9c7..c8a2f8f 100644 --- a/common/src/main/java/io/github/kosmx/bendylib/ICuboidBuilder.java +++ b/common/src/main/java/io/github/kosmx/bendylib/ICuboidBuilder.java @@ -19,11 +19,12 @@ class Data{ public int u, v; public boolean mirror = false; public int textureWidth, textureHeight; //That will be int + public int pivot; //public float bendX, bendY, bendZ; public Data(){} - public Data(int u, int v, float x, float y, float z, float sizeX, float sizeY, float sizeZ, float extraX, float extraY, float extraZ, boolean mirror, float textureWidth, float textureHeight){ + public Data(int u, int v, float x, float y, float z, float sizeX, float sizeY, float sizeZ, float extraX, float extraY, float extraZ, boolean mirror, float textureWidth, float textureHeight, int pivot) { this.u = u; this.v = v; this.x = x; @@ -36,10 +37,14 @@ public Data(int u, int v, float x, float y, float z, float sizeX, float sizeY, f this.extraY = extraY; this.extraZ = extraZ; this.mirror = mirror; + this.pivot = pivot; //Casting this.textureWidth = (int) textureWidth; this.textureHeight = (int) textureHeight; } + public Data(int u, int v, float x, float y, float z, float sizeX, float sizeY, float sizeZ, float extraX, float extraY, float extraZ, boolean mirror, float textureWidth, float textureHeight) { + this(u, v, x, y, z, sizeX, sizeY, sizeZ, extraX, extraY, extraZ, mirror, textureWidth, textureHeight, -1); + } } } diff --git a/common/src/main/java/io/github/kosmx/bendylib/compat/tr7zw/TDSkinCompat.java b/common/src/main/java/io/github/kosmx/bendylib/compat/tr7zw/TDSkinCompat.java deleted file mode 100644 index a42bd9a..0000000 --- a/common/src/main/java/io/github/kosmx/bendylib/compat/tr7zw/TDSkinCompat.java +++ /dev/null @@ -1,170 +0,0 @@ -package io.github.kosmx.bendylib.compat.tr7zw; - -import dev.tr7zw.skinlayers.api.MeshTransformer; -import dev.tr7zw.skinlayers.api.SkinLayersAPI; -import io.github.kosmx.bendylib.ModelPartAccessor; -import io.github.kosmx.bendylib.MutableCuboid; -import io.github.kosmx.bendylib.impl.BendableCuboid; -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.geom.ModelPart; -import net.minecraft.core.Direction; -import org.joml.Vector3f; -import org.joml.Vector4f; -import org.slf4j.Logger; - -import java.util.function.Consumer; - -public class TDSkinCompat { - public static void init() throws ClassNotFoundException, NoClassDefFoundError { - SkinLayersAPI.setupMeshTransformerProvider(modelPart -> { - var sourceCuboidOptional = ModelPartAccessor.optionalGetCuboid(modelPart, 0); - if (sourceCuboidOptional.isPresent() - && sourceCuboidOptional.get().getActiveMutator() != null - && sourceCuboidOptional.get().getActiveMutator().getB() instanceof BendableCuboid bendableSource) { - - - class Bender extends BendyMeshTransformer implements MeshTransformer { - - private Consumer transform = null; - - private Bender(BendableCuboid cuboid) { - super(cuboid); - applyBend(bendableSource.getBendAxis(), bendableSource.getBend(), consumer -> transform = consumer); - assert (transform != null); - } - - /** - * @param vec3f quad normal vector - * @param vector4fs quad vertices - */ - @Override - public void transform(Vector3f vec3f, Vector4f[] vector4fs) { - for (int i = 0; i < vector4fs.length; i++) { - var pos = new RememberingPos(new Vector3f(vector4fs[i].x, vector4fs[i].y, vector4fs[i].z)); - transform.accept(pos); - vector4fs[i] = new Vector4f(pos.getPos(), 1); - } - vec3f.set(calculateNormal(vector4fs)); - - } - - @Override - public void transform(ModelPart.Cube cuboid) { - var sourceCuboid = sourceCuboidOptional.get(); - var mutator = sourceCuboidOptional.get().getActiveMutator(); - - if (cuboid instanceof MutableCuboid mutableCuboid) { - 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) -> - new ModifiedBendableCuboid(sides, positions, minX, minY, minZ, maxX, maxY, maxZ, fixX, fixY, fixZ, direction, - getBasePlane().scaled(16), getOtherSidePlane().scaled(16), bendHeight()*16))); - } - - mutableCuboid.copyStateFrom(sourceCuboid); - - } - } - } - return new Bender(bendableSource) { - }; - } - return new MeshTransformer() { - @Override - public void transform(Vector3f vec3f, Vector4f[] vector4fs) { - //empty - } - - @Override - public void transform(ModelPart.Cube cuboid) { - ((MutableCuboid) cuboid).getAndActivateMutator(null); - } - }; - }); - } - - - public static Vector3f calculateNormal(Vector4f[] vertices) { - Vector3f buf = new Vector3f(vertices[3].x, vertices[3].y, vertices[3].z); - buf.negate(); - Vector3f vecB = new Vector3f(vertices[1].x, vertices[1].y, vertices[1].z); - vecB.add(buf); - buf = new Vector3f(vertices[2].x, vertices[2].y, vertices[2].z); - buf.negate(); - Vector3f vecA = new Vector3f(vertices[0].x, vertices[0].y, vertices[0].z); - 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.step(); - } - - private static class ModifiedBendableCuboid extends BendableCuboid { - - protected ModifiedBendableCuboid(Quad[] sides, RememberingPos[] positions, float minX, float minY, float minZ, float maxX, float maxY, float maxZ, float fixX, float fixY, float fixZ, Direction direction, Plane basePlane, Plane otherPlane, float fullSize) { - super(sides, positions, minX, minY, minZ, maxX, maxY, maxZ, fixX, fixY, fixZ, direction, basePlane, otherPlane, fullSize); - } - - } - - private static class BendyMeshTransformer implements IBendable { - private final Direction bendDirection; - private final float bendX, bendY, bendZ; - private final Plane basePlane, otherSidePlane; - - private final float bendHeight; - - private BendyMeshTransformer(Direction bendDirection, float bendX, float bendY, float bendZ, Plane basePlane, Plane otherSidePlane, float bendHeight) { - this.bendDirection = bendDirection; - this.bendX = bendX / 16; - this.bendY = bendY / 16; - this.bendZ = bendZ / 16; - this.basePlane = basePlane.scaled(1 / 16f); - this.otherSidePlane = otherSidePlane.scaled(1 / 16f); - this.bendHeight = bendHeight / 16; - } - - private BendyMeshTransformer(BendableCuboid cuboid) { - this(cuboid.getBendDirection(), cuboid.getBendX(), cuboid.getBendY(), cuboid.getBendZ(), - cuboid.getBasePlane(), cuboid.getOtherSidePlane(), cuboid.bendHeight()); - } - - @Override - public float bendHeight() { - return bendHeight; - } - - @Override - public Direction getBendDirection() { - return bendDirection; - } - - @Override - public float getBendX() { - return bendX; - } - - @Override - public float getBendY() { - return bendY; - } - - @Override - public float getBendZ() { - return bendZ; - } - - @Override - public Plane getBasePlane() { - return basePlane; - } - - @Override - public Plane getOtherSidePlane() { - return otherSidePlane; - } - } -} diff --git a/common/src/main/java/io/github/kosmx/bendylib/impl/BendableCuboid.java b/common/src/main/java/io/github/kosmx/bendylib/impl/BendableCuboid.java index dbcd398..a86cd47 100644 --- a/common/src/main/java/io/github/kosmx/bendylib/impl/BendableCuboid.java +++ b/common/src/main/java/io/github/kosmx/bendylib/impl/BendableCuboid.java @@ -174,20 +174,28 @@ public BendableCuboid build(Data data, BuildableBendable builder){ int p = data.v; int q = (int) (data.v + data.sizeZ); int r = (int) (data.v + data.sizeZ + data.sizeY); - createAndAddQuads(planes, positions, new Vector3f[]{vertex6, vertex5, vertex2}, k, p, l, q, data.textureWidth, data.textureHeight, data.mirror, data); - createAndAddQuads(planes, positions, new Vector3f[]{vertex3, vertex4, vertex7}, l, q, m, p, data.textureWidth, data.textureHeight, data.mirror, data); - createAndAddQuads(planes, positions, new Vector3f[]{vertex1, vertex5, vertex4}, j, q, k, r, data.textureWidth, data.textureHeight, data.mirror, data); - createAndAddQuads(planes, positions, new Vector3f[]{vertex2, vertex1, vertex3}, k, q, l, r, data.textureWidth, data.textureHeight, data.mirror, data); - 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); - + createAndAddQuads(planes, positions, new Vector3f[]{vertex6, vertex5, vertex2}, k, p, l, q, data); + createAndAddQuads(planes, positions, new Vector3f[]{vertex3, vertex4, vertex7}, l, q, m, p, data); + createAndAddQuads(planes, positions, new Vector3f[]{vertex1, vertex5, vertex4}, j, q, k, r, data); + createAndAddQuads(planes, positions, new Vector3f[]{vertex2, vertex1, vertex3}, k, q, l, r, data); + createAndAddQuads(planes, positions, new Vector3f[]{vertex6, vertex2, vertex7}, l, q, n, r, data); + createAndAddQuads(planes, positions, new Vector3f[]{vertex5, vertex6, vertex8}, n, q, o, r, data); + + Vector3f pivot = new Vector3f(0, 0, 0); + if (data.pivot >= 0) { + float size = direction.step().mul(maxX - minX, maxY - minY, maxZ - minZ).length(); + if (data.pivot <= size) { + pivot = direction.step().mul(size - (data.pivot * 2)); + vertex7 = vertex7.sub(pivot); + } + } + boolean bl = direction == Direction.UP || direction == Direction.SOUTH || direction == Direction.EAST; 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.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; + float bendX = (data.sizeX + data.x + data.x - pivot.x())/2; + float bendY = (data.sizeY + data.y + data.y - pivot.y())/2; + float bendZ = (data.sizeZ + data.z + data.z - pivot.z())/2; return builder.build(planes.toArray(new Quad[0]), positions.values().toArray(new RememberingPos[0]), minX, minY, minZ, maxX, maxY, maxZ, bendX, bendY, bendZ, direction, bl ? aPlane : bPlane, bl ? bPlane : aPlane, fullSize); } @@ -196,7 +204,7 @@ public BendableCuboid build(Data data) { } //edge[2] can be calculated from edge 0, 1, 3... - private void createAndAddQuads(Collection quads, HashMap positions, Vector3f[] edges, int u1, int v1, int u2, int v2, float squishU, float squishV, boolean flip, Data data){ + private void createAndAddQuads(Collection quads, HashMap positions, Vector3f[] edges, int u1, int v1, int u2, int v2, Data data){ int du = u2 < u1 ? 1 : -1; int dv = v1 < v2 ? 1 : -1; for(int localU = u2; localU != u1; localU += du){ diff --git a/fabric/build.gradle b/fabric/build.gradle index 7f267e9..a736b66 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -35,8 +35,6 @@ dependencies { modLocalRuntime "com.terraformersmc:modmenu:9.0.0" // modLocalRuntime "maven.modrinth:skinswapper:3.12" - modCompileOnly modLocalRuntime("maven.modrinth:3dskinlayers:1.5.2-1.19.3-fabric") - //modLocalRuntime "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}" // modLocalRuntime "dev.kosmx.player-anim:player-animation-lib-fabric:0.4.0-test1" //modLocalRuntime "maven.modrinth:emotecraft:2.2.5-MC1.19.2-fabric" diff --git a/fabric/src/main/java/io/github/kosmx/bendylib/fabric/Init.java b/fabric/src/main/java/io/github/kosmx/bendylib/fabric/Init.java index f8fbe7a..e9662a7 100644 --- a/fabric/src/main/java/io/github/kosmx/bendylib/fabric/Init.java +++ b/fabric/src/main/java/io/github/kosmx/bendylib/fabric/Init.java @@ -1,24 +1,8 @@ package io.github.kosmx.bendylib.fabric; -import io.github.kosmx.bendylib.compat.tr7zw.TDSkinCompat; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.loader.api.FabricLoader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class Init implements ClientModInitializer { - public static Logger LOGGER = LoggerFactory.getLogger("bendy-lib"); - @Override - public void onInitializeClient() { - if (FabricLoader.getInstance().isModLoaded("skinlayers")) { - LOGGER.info("Initializing 3D Skin Layers compatibility"); - - try { - TDSkinCompat.init(); - } catch(NoClassDefFoundError|ClassNotFoundException e) { - LOGGER.error("Failed to initialize 3D Skin Layers compatibility"); - } - } - } + public void onInitializeClient() {} } diff --git a/forge/build.gradle b/forge/build.gradle index d809e8f..7905122 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -24,8 +24,6 @@ dependencies { common(project(path: ":common", configuration: "namedElements")) { transitive false } shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false } - - //modCompileOnly modLocalRuntime("maven.modrinth:3dskinlayers:1.5.2-1.19.3-forge") } processResources { diff --git a/forge/src/main/java/io/github/kosmx/bendylib/neoforge/ForgeModInterface.java b/forge/src/main/java/io/github/kosmx/bendylib/neoforge/ForgeModInterface.java index 254cd25..9f140e7 100644 --- a/forge/src/main/java/io/github/kosmx/bendylib/neoforge/ForgeModInterface.java +++ b/forge/src/main/java/io/github/kosmx/bendylib/neoforge/ForgeModInterface.java @@ -1,25 +1,9 @@ package io.github.kosmx.bendylib.neoforge; -import io.github.kosmx.bendylib.compat.tr7zw.TDSkinCompat; import net.neoforged.api.distmarker.Dist; -import net.neoforged.fml.ModList; import net.neoforged.fml.common.Mod; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Mod(value = "bendylib", dist = Dist.CLIENT) public class ForgeModInterface { - public static Logger LOGGER = LoggerFactory.getLogger("bendy-lib"); - - public ForgeModInterface() { - if (ModList.get().isLoaded("skinlayers3d")) { - LOGGER.info("Initializing 3D Skin Layers compatibility"); - - try { - TDSkinCompat.init(); - } catch(NoClassDefFoundError|ClassNotFoundException e) { - LOGGER.error("Failed to initialize 3D Skin Layers compatibility"); - } - } - } + public ForgeModInterface() {} } diff --git a/gradle.properties b/gradle.properties index a1389c6..6819ddc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx4G -mod_version=5.0 +mod_version=5.1 maven_group=io.github.kosmx.bendy-lib archives_base_name=bendy-lib