Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.zigythebird.bendable_cuboids.api;

public interface Bendable {
float getBend();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.zigythebird.bendable_cuboids.api;

import com.zigythebird.bendable_cuboids.impl.Plane;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import org.joml.Matrix4f;

/**
* Should be pretty self-explanatory...
* Bend XYZ are the coordinates of the bend's center
* If you don't know the math behind it, don't try to edit.
* <p>
* Use {@link BendableCube#applyBend} to bend the cube
*/
public interface BendableCube extends Bendable {
/**
* Apply bend on this cuboid
* Values are in radians
* @param bendValue bend value (Same as rotX)
* @return Transformation matrix for transforming children
*/
Matrix4f applyBend(float bendValue);

default Matrix4f applyBendDegrees(float bendValue) {
return applyBend(bendValue * Mth.DEG_TO_RAD);
}

Direction getBendDirection();

float getBendX();
float getBendY();
float getBendZ();

Plane getBasePlane();
Plane getOtherPlane();

/**
* Distance between the two opposite surface of the cuboid.
* Calculate two plane distance is inefficient.
* Try to override it (If you have size)
* @return the size of the cube
*/
float bendHeight();

default boolean isBendInverted() {
return getBendDirection() == Direction.UP || getBendDirection() == Direction.SOUTH || getBendDirection() == Direction.EAST;
}

default void rebuild(Direction direction) {
rebuild(direction, -1);
}

void rebuild(Direction direction, int pivot);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.zigythebird.bendable_cuboids.api;

import org.jetbrains.annotations.Nullable;

public interface BendableModelPart {
/**
* Get a cuboid, and cast it to {@link BendableCube}
*/
@Nullable
BendableCube bc$getCuboid(int index);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import com.zigythebird.bendable_cuboids.api.BendableCube;
import com.zigythebird.bendable_cuboids.impl.compatibility.PlayerBendHelper;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.PlayerModel;
Expand All @@ -13,9 +14,9 @@
public class BendUtil {
private static final Vector3f Z_AXIS = new Vector3f(0, 0, 1);

public static BendApplier getBend(BendableCuboid cuboid, float bendValue) {
public static BendApplier getBend(BendableCube cuboid, float bendValue) {
return getBend(cuboid.getBendX(), cuboid.getBendY(), cuboid.getBendZ(),
cuboid.basePlane, cuboid.otherPlane, false, cuboid.bendHeight(), bendValue);
cuboid.getBasePlane(), cuboid.getOtherPlane(), false, cuboid.bendHeight(), bendValue);
}

/**
Expand All @@ -33,13 +34,13 @@ public static BendApplier getBend(float bendX, float bendY, float bendZ, Plane b
return new BendApplier(transformMatrix, pos -> {
float distFromBase = Math.abs(basePlane.distanceTo(pos));
float distFromOther = Math.abs(otherPlane.distanceTo(pos));
float s = (float) Math.clamp(Math.tan(finalBend/2)*pos.z, -2f, 2f);
float s = (float) Math.tan(finalBend/2)*pos.z;
if (mirrorBend) {
float temp = distFromBase;
distFromBase = distFromOther;
distFromOther = temp;
}
float v = halfSize - (s < 0 ? Math.abs(s)/2 : Math.abs(s));
float v = halfSize - (s < 0 ? Math.min(Math.abs(s)/2, 1) : Math.abs(s));
if (distFromBase < distFromOther) {
if (distFromBase + distFromOther <= bendHeight && distFromBase > v)
pos.y = bendY + s;
Expand All @@ -54,9 +55,9 @@ else if (distFromBase + distFromOther <= bendHeight && distFromOther > v) {
});
}

public static BendApplier getBendLegacy(BendableCuboid cuboid, float bendValue) {
public static BendApplier getBendLegacy(BendableCube cuboid, float bendValue) {
return getBendLegacy(cuboid.getBendDirection(), cuboid.getBendX(), cuboid.getBendY(), cuboid.getBendZ(),
cuboid.basePlane, cuboid.otherPlane, cuboid.isBendInverted(), false, cuboid.bendHeight(), bendValue);
cuboid.getBasePlane(), cuboid.getOtherPlane(), cuboid.isBendInverted(), false, cuboid.bendHeight(), bendValue);
}

/**
Expand Down
Loading