forked from Upstream/mmocore
Changes 3D Gui.
This commit is contained in:
parent
28556182a3
commit
4d08a98ed2
@ -18,11 +18,11 @@ import java.util.logging.Level;
|
|||||||
public abstract class EditableInventory {
|
public abstract class EditableInventory {
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
|
private FileConfiguration config;
|
||||||
private AdaptorType adaptorType;
|
private AdaptorType adaptorType;
|
||||||
private String name;
|
private String name;
|
||||||
private int slots;
|
private int slots;
|
||||||
|
|
||||||
protected double radius, angleGap, verticalGap, curvature, verticalOffset, interactSensitivity;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This set is linked so it keeps the order/priority in
|
* This set is linked so it keeps the order/priority in
|
||||||
@ -38,17 +38,10 @@ public abstract class EditableInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reload(FileConfiguration config) {
|
public void reload(FileConfiguration config) {
|
||||||
|
this.config = config;
|
||||||
this.adaptorType = AdaptorType.valueOf(MMOCoreUtils.toEnumName(config.getString("adaptor-type", "classic-adaptor")));
|
this.adaptorType = AdaptorType.valueOf(MMOCoreUtils.toEnumName(config.getString("adaptor-type", "classic-adaptor")));
|
||||||
Validate.notNull(adaptorType, config.getString("adaptor-type") + " does not correspond to an adaptor-type.");//TODO
|
Validate.notNull(adaptorType, config.getString("adaptor-type") + " does not correspond to an adaptor-type.");//TODO
|
||||||
|
|
||||||
this.radius = config.getDouble("radius", 2);
|
|
||||||
this.angleGap = config.getDouble("angle-gap", 10);
|
|
||||||
this.verticalGap = config.getDouble("vertical-gap", 1);
|
|
||||||
this.curvature = config.getDouble("curvature", 1);
|
|
||||||
this.verticalOffset = config.getDouble("vertical-offset", 0);
|
|
||||||
this.interactSensitivity = config.getDouble("interact-sensitivity", 0.97);
|
|
||||||
|
|
||||||
this.name = config.getString("name");
|
this.name = config.getString("name");
|
||||||
Validate.notNull(name, "Name must not be null");
|
Validate.notNull(name, "Name must not be null");
|
||||||
|
|
||||||
@ -90,28 +83,9 @@ public abstract class EditableInventory {
|
|||||||
return adaptorType;
|
return adaptorType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getRadius() {
|
|
||||||
return radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getAngleGap() {
|
public FileConfiguration getConfig() {
|
||||||
return angleGap;
|
return config;
|
||||||
}
|
|
||||||
|
|
||||||
public double getVerticalGap() {
|
|
||||||
return verticalGap;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getInteractSensitivity() {
|
|
||||||
return interactSensitivity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getCurvature() {
|
|
||||||
return curvature;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getVerticalOffset() {
|
|
||||||
return verticalOffset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryItem getByFunction(String function) {
|
public InventoryItem getByFunction(String function) {
|
||||||
|
@ -20,7 +20,6 @@ public abstract class GeneratedInventory extends PluginInventory {
|
|||||||
|
|
||||||
public GeneratedInventory(PlayerData playerData, EditableInventory editable) {
|
public GeneratedInventory(PlayerData playerData, EditableInventory editable) {
|
||||||
super(playerData);
|
super(playerData);
|
||||||
|
|
||||||
this.editable = editable;
|
this.editable = editable;
|
||||||
this.adaptor = editable.getAdaptorType().supply(this);
|
this.adaptor = editable.getAdaptorType().supply(this);
|
||||||
}
|
}
|
||||||
@ -30,6 +29,7 @@ public abstract class GeneratedInventory extends PluginInventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public EditableInventory getEditable() {
|
public EditableInventory getEditable() {
|
||||||
|
|
||||||
return editable;
|
return editable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +62,8 @@ public abstract class GeneratedInventory extends PluginInventory {
|
|||||||
return ((ClassicAdaptor) adaptor).getInventory();
|
return ((ClassicAdaptor) adaptor).getInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void open() {
|
public void open() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Very important, in order to prevent ghost items, the loaded items map
|
* Very important, in order to prevent ghost items, the loaded items map
|
||||||
* must be cleared when the inventory is updated or open at least twice
|
* must be cleared when the inventory is updated or open at least twice
|
||||||
@ -83,6 +83,7 @@ public abstract class GeneratedInventory extends PluginInventory {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void whenClicked(InventoryClickContext context) {
|
public void whenClicked(InventoryClickContext context) {
|
||||||
context.setCancelled(true);
|
context.setCancelled(true);
|
||||||
InventoryItem item = getBySlot(context.getSlot());
|
InventoryItem item = getBySlot(context.getSlot());
|
||||||
|
@ -48,10 +48,13 @@ public class ThreeDimAdaptor extends Adaptor {
|
|||||||
|
|
||||||
private final HashMap<ItemStack, ArmorStand> hiddenArmorStand = new HashMap<>();
|
private final HashMap<ItemStack, ArmorStand> hiddenArmorStand = new HashMap<>();
|
||||||
|
|
||||||
|
protected double radius, angleGap, verticalGap, curvature, verticalOffset, interactSensitivity;
|
||||||
|
|
||||||
|
|
||||||
private boolean firstTime = true;
|
private boolean firstTime = true;
|
||||||
|
|
||||||
private final Vector direction = generated.getPlayer().getEyeLocation().getDirection().setY(0);
|
private final Vector direction = generated.getPlayer().getEyeLocation().getDirection().setY(0);
|
||||||
private final Location location = generated.getPlayer().getLocation().add(new Vector(0, generated.getEditable().getVerticalOffset(), 0));
|
private final Location location;
|
||||||
|
|
||||||
//Zoomed=-1 no armorstand are under zoom
|
//Zoomed=-1 no armorstand are under zoom
|
||||||
private int zoomed = -1;
|
private int zoomed = -1;
|
||||||
@ -59,6 +62,14 @@ public class ThreeDimAdaptor extends Adaptor {
|
|||||||
|
|
||||||
public ThreeDimAdaptor(GeneratedInventory generated) {
|
public ThreeDimAdaptor(GeneratedInventory generated) {
|
||||||
super(generated);
|
super(generated);
|
||||||
|
|
||||||
|
this.radius = generated.getEditable().getConfig().getDouble("radius", 2);
|
||||||
|
this.angleGap = generated.getEditable().getConfig().getDouble("angle-gap", 10);
|
||||||
|
this.verticalGap = generated.getEditable().getConfig().getDouble("vertical-gap", 1);
|
||||||
|
this.curvature = generated.getEditable().getConfig().getDouble("curvature", 1);
|
||||||
|
this.verticalOffset = generated.getEditable().getConfig().getDouble("vertical-offset", 0);
|
||||||
|
this.interactSensitivity = generated.getEditable().getConfig().getDouble("interact-sensitivity", 0.97);
|
||||||
|
location = generated.getPlayer().getLocation().add(new Vector(0, verticalOffset, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -180,9 +191,12 @@ public class ThreeDimAdaptor extends Adaptor {
|
|||||||
|
|
||||||
private void setItem(ItemStack item, int n, double percentage) {
|
private void setItem(ItemStack item, int n, double percentage) {
|
||||||
Location location = getLocation(n, percentage);
|
Location location = getLocation(n, percentage);
|
||||||
|
if(item.getType().toString().contains("SKULL")||item.getType().toString().contains("HEAD")) {
|
||||||
|
location.add(new Vector(0,4.9,0));
|
||||||
|
}
|
||||||
//We create the armorStand corresponding to display the item
|
//We create the armorStand corresponding to display the item
|
||||||
ArmorStand armorStand = (ArmorStand) generated.getPlayer().getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
|
ArmorStand armorStand = (ArmorStand) generated.getPlayer().getWorld().spawnEntity(location, EntityType.ARMOR_STAND);
|
||||||
armorStand.setVisible(false);
|
armorStand.setVisible(true);
|
||||||
armorStand.setSmall(false);
|
armorStand.setSmall(false);
|
||||||
armorStand.setArms(true);
|
armorStand.setArms(true);
|
||||||
armorStand.setGravity(false);
|
armorStand.setGravity(false);
|
||||||
@ -317,13 +331,13 @@ public class ThreeDimAdaptor extends Adaptor {
|
|||||||
|
|
||||||
Location cloneLocation = location.clone();
|
Location cloneLocation = location.clone();
|
||||||
Vector cloneDirection = direction.clone().rotateAroundAxis(new Vector(0, 1, 0),
|
Vector cloneDirection = direction.clone().rotateAroundAxis(new Vector(0, 1, 0),
|
||||||
-((n % 9) - 4) * generated.getEditable().getAngleGap() * Math.PI / 180);
|
-((n % 9) - 4) * angleGap * Math.PI / 180);
|
||||||
|
|
||||||
//Curvature of 1: r=cst Curvature of 1: r=R/cos(angle) (a plane)
|
//Curvature of 1: r=cst Curvature of 1: r=R/cos(angle) (a plane)
|
||||||
double radius = percentage * generated.getEditable().getRadius() / Math.cos((1 - generated.getEditable().getCurvature())
|
double radius = percentage * this.radius / Math.cos((1 - curvature)
|
||||||
* -((n % 9) - 4) * generated.getEditable().getAngleGap() * Math.PI / 180);
|
* -((n % 9) - 4) * angleGap * Math.PI / 180);
|
||||||
cloneDirection = cloneDirection.normalize().multiply(radius);
|
cloneDirection = cloneDirection.normalize().multiply(radius);
|
||||||
cloneDirection.add(new Vector(0, percentage * generated.getEditable().getVerticalGap() * ((generated.getEditable().getSlots() - n - 1) / 9), 1));
|
cloneDirection.add(new Vector(0, percentage * verticalGap * ((generated.getEditable().getSlots() - n - 1) / 9), 1));
|
||||||
//We get the final direction
|
//We get the final direction
|
||||||
cloneLocation.add(cloneDirection);
|
cloneLocation.add(cloneDirection);
|
||||||
|
|
||||||
@ -380,15 +394,8 @@ public class ThreeDimAdaptor extends Adaptor {
|
|||||||
if (!e.getFrom().getBlock().getLocation().equals(e.getTo().getBlock().getLocation()))
|
if (!e.getFrom().getBlock().getLocation().equals(e.getTo().getBlock().getLocation()))
|
||||||
ThreeDimAdaptor.this.close();
|
ThreeDimAdaptor.this.close();
|
||||||
else {
|
else {
|
||||||
//If the player no longer looks at the zoom as:
|
int closest = -1;
|
||||||
if (zoomed != -1 && generated.getPlayer().getLocation().getDirection().normalize().dot(
|
double closestScalar = 1;
|
||||||
armorStands.get(zoomed).getLocation().add(new Vector(0, 0.25 * armorStands.get(zoomed).getHeight(), 0))
|
|
||||||
.subtract(generated.getPlayer().getLocation()).toVector().normalize()) < generated.getEditable().getInteractSensitivity()) {
|
|
||||||
armorStands.get(zoomed).teleport(getLocation(zoomed, 1));
|
|
||||||
zoomed = -1;
|
|
||||||
removeLore();
|
|
||||||
}
|
|
||||||
if (zoomed == -1) {
|
|
||||||
for (int n : armorStands.keySet()) {
|
for (int n : armorStands.keySet()) {
|
||||||
ArmorStand as = armorStands.get(n);
|
ArmorStand as = armorStands.get(n);
|
||||||
Location asLocation = as.getLocation().add(new Vector(0, 0.25 * as.getHeight(), 0));
|
Location asLocation = as.getLocation().add(new Vector(0, 0.25 * as.getHeight(), 0));
|
||||||
@ -397,16 +404,26 @@ public class ThreeDimAdaptor extends Adaptor {
|
|||||||
double scalar = generated.getPlayer().getLocation().getDirection().normalize().dot(
|
double scalar = generated.getPlayer().getLocation().getDirection().normalize().dot(
|
||||||
asLocation.subtract(generated.getPlayer().getLocation()).toVector().normalize());
|
asLocation.subtract(generated.getPlayer().getLocation()).toVector().normalize());
|
||||||
|
|
||||||
if (scalar > generated.getEditable().getInteractSensitivity()) {
|
if (scalar > interactSensitivity && scalar < closestScalar) {
|
||||||
as.teleport(getLocation(n, 0.75));
|
closestScalar = scalar;
|
||||||
zoomed = n;
|
closest = n;
|
||||||
displayLore(zoomed);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (closest != zoomed) {
|
||||||
|
if (zoomed != -1) {
|
||||||
|
removeLore();
|
||||||
|
armorStands.get(zoomed).teleport(getLocation(zoomed, 1));
|
||||||
|
}
|
||||||
|
if (closest != -1) {
|
||||||
|
armorStands.get(zoomed).teleport(getLocation(closest, 0.75));
|
||||||
|
zoomed = closest;
|
||||||
|
displayLore(closest);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -416,7 +433,11 @@ public class ThreeDimAdaptor extends Adaptor {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInteract(PlayerInteractAtEntityEvent event) {
|
public void onInteract(PlayerInteractAtEntityEvent event) {
|
||||||
if (event.getPlayer().equals(generated.getPlayer()))
|
if (event.getPlayer().equals(generated.getPlayer()))
|
||||||
if (event.getRightClicked() instanceof ArmorStand armorStand) {
|
if (event.getRightClicked() instanceof ArmorStand armorStand)
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
if (armorStands.values().contains(armorStand)) {
|
if (armorStands.values().contains(armorStand)) {
|
||||||
PersistentDataContainer container = armorStand.getPersistentDataContainer();
|
PersistentDataContainer container = armorStand.getPersistentDataContainer();
|
||||||
int slot = container.get(new NamespacedKey(MMOCore.plugin, "slot"), PersistentDataType.INTEGER);
|
int slot = container.get(new NamespacedKey(MMOCore.plugin, "slot"), PersistentDataType.INTEGER);
|
||||||
@ -428,6 +449,7 @@ public class ThreeDimAdaptor extends Adaptor {
|
|||||||
generated.whenClicked(new InventoryClickContext(slot, armorStand.getEquipment().getItem(EquipmentSlot.HEAD), clickType, event));
|
generated.whenClicked(new InventoryClickContext(slot, armorStand.getEquipment().getItem(EquipmentSlot.HEAD), clickType, event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -465,35 +487,40 @@ public class ThreeDimAdaptor extends Adaptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDamage(EntityDamageByEntityEvent event) {
|
public void onDamage(EntityDamageByEntityEvent event) {
|
||||||
|
if (event.getDamager() instanceof Player player)
|
||||||
if (event.getDamager() instanceof Player player) {
|
|
||||||
if (player.equals(generated.getPlayer()))
|
if (player.equals(generated.getPlayer()))
|
||||||
if (event.getEntity() instanceof ArmorStand armorStand) {
|
if (event.getEntity() instanceof ArmorStand armorStand)
|
||||||
if (armorStands.values().contains(armorStand)) {
|
if (armorStands.values().contains(armorStand))
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
PersistentDataContainer container = armorStand.getPersistentDataContainer();
|
PersistentDataContainer container = armorStand.getPersistentDataContainer();
|
||||||
int slot = container.get(new NamespacedKey(MMOCore.plugin, "slot"), PersistentDataType.INTEGER);
|
int slot = container.get(new NamespacedKey(MMOCore.plugin, "slot"), PersistentDataType.INTEGER);
|
||||||
ClickType clickType;
|
ClickType clickType;
|
||||||
if (player.isSneaking())
|
if(player.isSneaking())
|
||||||
clickType = ClickType.SHIFT_LEFT;
|
clickType =ClickType.SHIFT_LEFT;
|
||||||
else
|
else
|
||||||
clickType = ClickType.LEFT;
|
clickType =ClickType.LEFT;
|
||||||
|
|
||||||
ItemStack itemStack = armorStand.getEquipment().getItem(EquipmentSlot.HEAD);
|
ItemStack itemStack = armorStand.getEquipment().getItem(EquipmentSlot.HEAD);
|
||||||
generated.whenClicked(new InventoryClickContext(slot, itemStack, clickType, event));
|
generated.whenClicked(new
|
||||||
}
|
|
||||||
|
InventoryClickContext(slot, itemStack, clickType, event));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
*/
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenClosed() {
|
public void whenClosed() {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user