Skip to content

Commit

Permalink
[1.5] - Add hitbox override GUI setting and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Luncaaa committed Jul 12, 2024
1 parent 041a793 commit 60f17b4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public interface BaseDisplay {
*/

void setRotation(float yaw, float pitch);

/**
* Sets the display's rotation for a specific player.
* @param yaw The new yaw.
Expand Down Expand Up @@ -231,6 +232,12 @@ public interface BaseDisplay {
*/
float getHitboxHeight();

/**
* Returns whether the display uses an automatic hitbox size or it was set automatically.
* @return Whether the display uses an automatic hitbox size or it was set automatically.
*/
boolean isHitboxSizeOverriden();

/**
* Sets the code to run when the display is clicked.
* @param actions The code to run.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public ConfigAxisAngle4f() {
}

public ConfigAxisAngle4f(Quaternionf angle) {
angle.normalize();
this.a = (float) Math.toDegrees(angle.angle());

float sinHalfAngle = (float) Math.sqrt(1.0 - angle.w * angle.w);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ public void setGlowColor(Color color, Player player) {
@Override
public void setHitboxSize(boolean override, float width, float height) {
this.overrideHitboxSize = override;
this.hitboxWidth = width;
this.hitboxHeight = height;
this.hitboxWidth = (override) ? width : this.transformation.getScale().x;
this.hitboxHeight = (override) ? height : this.transformation.getScale().y;

if (this.config != null) {
ConfigurationSection hitboxSection = Objects.requireNonNull(this.config.getConfigurationSection("hitbox"));
Expand All @@ -475,12 +475,10 @@ public void setHitboxSize(boolean override, float width, float height) {
this.save();
}

if (override) {
this.hitbox.setInteractionWidth(transformation.getScale().x);
this.hitbox.setInteractionHeight(transformation.getScale().y);
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
this.packets.setInteractionSize(this.hitbox.getEntityId(), width, height, onlinePlayer);
}
this.hitbox.setInteractionWidth(this.hitboxWidth);
this.hitbox.setInteractionHeight(this.hitboxHeight);
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
this.packets.setInteractionSize(this.hitbox.getEntityId(), this.hitboxWidth, this.hitboxHeight, onlinePlayer);
}
}

Expand All @@ -494,6 +492,11 @@ public float getHitboxHeight() {
return this.hitboxHeight;
}

@Override
public boolean isHitboxSizeOverriden() {
return this.overrideHitboxSize;
}

@Override
public void setClickActions(DisplayActions actions) {
this.actionsHandler.setClickActions(actions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ public void onClick(InventoryClickEvent event) {
display.setBillboard(newBillboard);
}
});

addButton(12, new Button.InventoryButton(items.HITBOX_OVERRIDE) {
@Override
public void onClick(InventoryClickEvent event) {
boolean newValue = InventoryUtils.changeBooleanValue(getItem(), display.isHitboxSizeOverriden());
getInventory().setItem(12, getItem());
display.setHitboxSize(newValue, display.getHitboxWidth(), display.getHitboxHeight());
}
});
// ----------

// ----[ ACTIONS ]-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Transformation;
import org.joml.AxisAngle4f;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -199,7 +198,7 @@ private void addLeftRotButtons(InventoryItems items) {
public void onClick(PlayerInteractEvent event) {
double newValue = InventoryUtils.changeDoubleValue(getItem(), transformation.getLeftRotation().x, event.getPlayer().isSneaking(), 0.0, 1.0, isLeftClick(event), true);
player.getInventory().setItem(0, getItem());
transformation.getLeftRotation().set(new AxisAngle4f(transformation.getLeftRotation().angle(), (float) newValue, transformation.getLeftRotation().y, transformation.getLeftRotation().z));
transformation.getLeftRotation().setAngleAxis(transformation.getLeftRotation().angle(), (float) newValue, transformation.getLeftRotation().y, transformation.getLeftRotation().z);
display.setTransformation(transformation);
}
});
Expand All @@ -209,7 +208,7 @@ public void onClick(PlayerInteractEvent event) {
public void onClick(PlayerInteractEvent event) {
double newValue = InventoryUtils.changeDoubleValue(getItem(), transformation.getLeftRotation().y, event.getPlayer().isSneaking(), 0.0, 1.0, isLeftClick(event), true);
player.getInventory().setItem(1, getItem());
transformation.getLeftRotation().set(new AxisAngle4f(transformation.getLeftRotation().angle(), transformation.getLeftRotation().x, (float) newValue, transformation.getLeftRotation().z));
transformation.getLeftRotation().setAngleAxis(transformation.getLeftRotation().angle(), transformation.getLeftRotation().x, (float) newValue, transformation.getLeftRotation().z);
display.setTransformation(transformation);
}
});
Expand All @@ -219,7 +218,7 @@ public void onClick(PlayerInteractEvent event) {
public void onClick(PlayerInteractEvent event) {
double newValue = InventoryUtils.changeDoubleValue(getItem(), transformation.getLeftRotation().z, event.getPlayer().isSneaking(), 0.0, 1.0, isLeftClick(event), true);
player.getInventory().setItem(2, getItem());
transformation.getLeftRotation().set(new AxisAngle4f(transformation.getLeftRotation().angle(), transformation.getLeftRotation().x, transformation.getLeftRotation().y, (float) newValue));
transformation.getLeftRotation().setAngleAxis(transformation.getLeftRotation().angle(), transformation.getLeftRotation().x, transformation.getLeftRotation().y, (float) newValue);
display.setTransformation(transformation);
}
});
Expand All @@ -229,7 +228,7 @@ public void onClick(PlayerInteractEvent event) {
public void onClick(PlayerInteractEvent event) {
double newValue = InventoryUtils.changeDoubleValue(getItem(), Math.toDegrees(transformation.getLeftRotation().angle()), 10.0, 1.0, event.getPlayer().isSneaking(), 0.0, null, isLeftClick(event), true);
player.getInventory().setItem(3, getItem());
transformation.getLeftRotation().set(new AxisAngle4f((float) Math.toRadians(newValue), transformation.getLeftRotation().x, transformation.getLeftRotation().y, transformation.getLeftRotation().z));
transformation.getLeftRotation().setAngleAxis((float) Math.toRadians(newValue), transformation.getLeftRotation().x, transformation.getLeftRotation().y, transformation.getLeftRotation().z);
display.setTransformation(transformation);
}
});
Expand Down Expand Up @@ -263,7 +262,7 @@ private void addRightRotButtons(InventoryItems items) {
public void onClick(PlayerInteractEvent event) {
double newValue = InventoryUtils.changeDoubleValue(getItem(), transformation.getRightRotation().x, event.getPlayer().isSneaking(), 0.0, 1.0, isLeftClick(event), true);
player.getInventory().setItem(0, getItem());
transformation.getRightRotation().set(new AxisAngle4f(transformation.getRightRotation().angle(), (float) newValue, transformation.getRightRotation().y, transformation.getRightRotation().z));
transformation.getRightRotation().setAngleAxis(transformation.getRightRotation().angle(), (float) newValue, transformation.getRightRotation().y, transformation.getRightRotation().z);
display.setTransformation(transformation);
}
});
Expand All @@ -273,7 +272,7 @@ public void onClick(PlayerInteractEvent event) {
public void onClick(PlayerInteractEvent event) {
double newValue = InventoryUtils.changeDoubleValue(getItem(), transformation.getRightRotation().y, event.getPlayer().isSneaking(), 0.0, 1.0, isLeftClick(event), true);
player.getInventory().setItem(1, getItem());
transformation.getRightRotation().set(new AxisAngle4f(transformation.getRightRotation().angle(), transformation.getRightRotation().x, (float) newValue, transformation.getRightRotation().z));
transformation.getRightRotation().setAngleAxis(transformation.getRightRotation().angle(), transformation.getRightRotation().x, (float) newValue, transformation.getRightRotation().z);
display.setTransformation(transformation);
}
});
Expand All @@ -283,7 +282,7 @@ public void onClick(PlayerInteractEvent event) {
public void onClick(PlayerInteractEvent event) {
double newValue = InventoryUtils.changeDoubleValue(getItem(), transformation.getRightRotation().z, event.getPlayer().isSneaking(), 0.0, 1.0, isLeftClick(event), true);
player.getInventory().setItem(2, getItem());
transformation.getRightRotation().set(new AxisAngle4f(transformation.getRightRotation().angle(), transformation.getRightRotation().x, transformation.getRightRotation().y, (float) newValue));
transformation.getRightRotation().setAngleAxis(transformation.getRightRotation().angle(), transformation.getRightRotation().x, transformation.getRightRotation().y, (float) newValue);
display.setTransformation(transformation);
}
});
Expand All @@ -293,7 +292,7 @@ public void onClick(PlayerInteractEvent event) {
public void onClick(PlayerInteractEvent event) {
double newValue = InventoryUtils.changeDoubleValue(getItem(), Math.toDegrees(transformation.getRightRotation().angle()), 10.0, 1.0, event.getPlayer().isSneaking(), 0.0, null, isLeftClick(event), true);
player.getInventory().setItem(3, getItem());
transformation.getRightRotation().set(new AxisAngle4f((float) Math.toRadians(newValue), transformation.getRightRotation().x, transformation.getRightRotation().y, transformation.getRightRotation().z));
transformation.getRightRotation().setAngleAxis((float) Math.toRadians(newValue), transformation.getRightRotation().x, transformation.getRightRotation().y, transformation.getRightRotation().z);
display.setTransformation(transformation);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class EditorItems {
public final ItemStack CENTER;

public final ItemStack BILLBOARD;
public final ItemStack HITBOX_OVERRIDE;

public final ItemStack CURRENT_VALUE;
public final ItemStack REMOVE;
Expand Down Expand Up @@ -63,6 +64,7 @@ public EditorItems(BaseDisplay display) {
CENTER = GlobalItems.create(Material.LIGHTNING_ROD, "Center", "Centers the display on the block it's on", location);

BILLBOARD = GlobalItems.create(Material.STRUCTURE_VOID, "Change billboard", "Changes the display's rotation axis", display.getBillboard().name());
HITBOX_OVERRIDE = GlobalItems.create(Material.END_CRYSTAL, "Override hitbox size", List.of("Whether the hitbox size is set", "automatically or manually"), display.isHitboxSizeOverriden(), false);

switch (display.getType()) {
case TEXT -> CURRENT_VALUE = GlobalItems.create(Material.OAK_SIGN, "Display text", List.of("Changes the text that is being displayed", "", "&7Use &cLEFT_CLICK &7to remove an animation", "&7Use &cRIGHT_CLICK &7to add an animation"), ((TextDisplay) display).getText().size() + " text animation(s)", false, false, 0.0, 0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public InventoryItems(BaseDisplay display) {
LEFT_ROTATION_X = GlobalItems.create(Material.BLAZE_ROD, "Left Rotation X", "Changes the x component of the display's left rotation", transformation.getLeftRotation().x, true, true, 1.0, 0.1, true);
LEFT_ROTATION_Y = GlobalItems.create(Material.BLAZE_ROD, "Left Rotation Y", "Changes the y component of the display's left rotation", transformation.getLeftRotation().y, true, true, 1.0, 0.1, true);
LEFT_ROTATION_Z = GlobalItems.create(Material.BLAZE_ROD, "Left Rotation Z", "Changes the z component of the display's left rotation", transformation.getLeftRotation().z, true, true, 1.0, 0.1, true);
LEFT_ROTATION_ANGLE = GlobalItems.create(Material.MAGMA_CREAM, "Left Rotation Angle", "Changes the angle of the display's left rotation", Math.toDegrees(transformation.getLeftRotation().angle()), true, true, 10.0, 1.0, true);
LEFT_ROTATION_ANGLE = GlobalItems.create(Material.MAGMA_CREAM, "Left Rotation Angle", "Changes the angle of the display's left rotation", BigDecimal.valueOf(Math.toDegrees(transformation.getLeftRotation().angle())).setScale(2, RoundingMode.HALF_UP).doubleValue(), true, true, 10.0, 1.0, true);

YAW = GlobalItems.create(Material.SLIME_BALL, "Yaw", "Changes the display's yaw", display.getYaw(), true, true, 10.0, 1.0, true);
PITCH = GlobalItems.create(Material.FIRE_CHARGE, "Pitch", "Changes the display's pitch", display.getPitch(), true, true, 10.0, 1.0, true);
Expand All @@ -70,8 +70,8 @@ public InventoryItems(BaseDisplay display) {
RIGHT_ROTATION_Z = GlobalItems.create(Material.STICK, "Left Rotation Z", "Changes the z component of the display's right rotation", transformation.getRightRotation().z, true, true, 1.0, 0.1, true);
RIGHT_ROTATION_ANGLE = GlobalItems.create(Material.MAGMA_CREAM, "Right Rotation Angle", "Changes the angle of the display's right rotation", BigDecimal.valueOf(Math.toDegrees(transformation.getRightRotation().angle())).setScale(2, RoundingMode.HALF_UP).doubleValue(), true, true, 10.0, 1.0, true);

HITBOX_WIDTH = GlobalItems.create(Material.LEATHER, "Hitbox width", List.of("Changes the width of the display's hitbox.", "It will automatically set the hitbox size override to true"), display.getHitboxWidth(), true, true, 1.0, 0.1, true);
HITBOX_HEIGHT = GlobalItems.create(Material.RABBIT_HIDE, "Hitbox height", List.of("Changes the height of the display's hitbox.", "It will automatically set the hitbox size override to true"), display.getHitboxHeight(), true, true, 1.0, 0.1, true);
HITBOX_WIDTH = GlobalItems.create(Material.LEATHER, "Hitbox width", List.of("Changes the width of the display's hitbox.", "It will automatically set the hitbox size override to true,", "although you can change it to false in the GUI"), display.getHitboxWidth(), true, true, 1.0, 0.1, true);
HITBOX_HEIGHT = GlobalItems.create(Material.RABBIT_HIDE, "Hitbox height", List.of("Changes the height of the display's hitbox.", "It will automatically set the hitbox size override to true,", "although you can change it to false in the GUI"), display.getHitboxHeight(), true, true, 1.0, 0.1, true);

OPEN_GUI = GlobalItems.create(Material.NETHER_STAR, "Open editor GUI", List.of("Opens a GUI with more options", "to edit the display"), "(" + display.getType() + ") " + display.getName(), false);
CHANGE_ROW = GlobalItems.create(Material.ARROW, "Change row", List.of("Changes the tools in your hotbar", "with another row of tools"), PlayerInv.InventoryRows.LEFT_ROTATION_YAW_PITCH.getName(), true);
Expand Down

0 comments on commit 60f17b4

Please sign in to comment.