Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Item Display rotations incorrect in versions after 1.19.4 #80

Merged
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
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 @@ -2,12 +2,15 @@

import dev.sefiraat.sefilib.misc.RotationFace;
import dev.sefiraat.sefilib.misc.TransformationBuilder;
import io.papermc.lib.PaperLib;
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 +140,18 @@ public enum Transformations {
}

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

public Transformation getTransformation(boolean itemDisplay) {
// In 1.20+ the y-axis of item displays are rotated by 180°
// This corrects the visuals by rotating again
if (itemDisplay && PaperLib.getMinecraftVersion() >= 20) {
return new Transformation(transformation.getTranslation(),
transformation.getLeftRotation(),
transformation.getScale(),
new Quaternionf(transformation.getRightRotation()).rotateY((float) Math.PI));
}
return transformation;
}
}
Loading