Skip to content

Commit

Permalink
fix transformationsssss
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Mar 5, 2024
1 parent b1dfa47 commit 5e24032
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public static DisplayGroup generatePlant(@Nonnull Location location) {
"plant",
new ItemDisplayBuilder()
.setGroupParentOffset(new Vector(0, 0.5, 0))
.setTransformation(Transformations.DEFAULT_TRANSFORMATION.getTransformation())
.setItemStack(new ItemStack(Material.SMALL_DRIPLEAF))
.build(displayGroup)
);
Expand Down Expand Up @@ -355,7 +356,7 @@ public static DisplayGroup generateGrindingCounter(@Nonnull Location location) {
new BlockDisplayBuilder()
.setGroupParentOffset(new Vector(0.1, 0.82, -0.2))
.setBlockData(blockData)
.setTransformation(Transformations.GRINDING_BOWL.getTransformation())
.setTransformation(Transformations.GRINDING_BOWL.getTransformation(false))
.build(displayGroup)
);
displayGroup.addDisplay(
Expand Down Expand Up @@ -428,7 +429,7 @@ public static DisplayGroup generateBoilingCounter(@Nonnull Location location) {
new BlockDisplayBuilder()
.setGroupParentOffset(new Vector(-0.15, 0.85, -0.15))
.setBlockData(blockData)
.setTransformation(Transformations.BOILING_POT.getTransformation())
.setTransformation(Transformations.BOILING_POT.getTransformation(false))
.build(displayGroup)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import dev.sefiraat.sefilib.misc.RotationFace;
import dev.sefiraat.sefilib.misc.TransformationBuilder;
import org.bukkit.util.Transformation;
import org.joml.Quaternionf;

import javax.annotation.Nonnull;

public enum Transformations {

DEFAULT_TRANSFORMATION(new TransformationBuilder().build()),
STICK_POINT_UPRIGHT(new TransformationBuilder()
.firstRotation(RotationFace.FRONT, 45)
.build()
Expand Down Expand Up @@ -137,6 +139,17 @@ public enum Transformations {
}

public Transformation getTransformation() {
return getTransformation(true);
}

public Transformation getTransformation(boolean itemDisplay) {
// 1.20 added 180 degrees to item display rotation, let's account for this
if (itemDisplay && Utils.getMajorServerVersion() >= 20) {
return new Transformation(transformation.getTranslation(),
transformation.getLeftRotation(),
transformation.getScale(),
new Quaternionf(transformation.getRightRotation()).rotateY((float) Math.PI));
}
return transformation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.sefiraat.cultivation.implementation.utils;

import org.bukkit.Bukkit;

public class Utils {

private Utils() {
throw new IllegalStateException("Utility class");
}

public static int getMajorServerVersion() {
return Integer.parseInt(Bukkit.getServer().getBukkitVersion().split("\\.")[1]);
}
}

0 comments on commit 5e24032

Please sign in to comment.