From 91711401c0eea4d2cad60e207366da385e5b0339 Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Wed, 12 Aug 2020 13:10:57 +0200 Subject: [PATCH] Added options for the pathfinder --- .../entity/pathfinding/PFPathingEntity.java | 79 +++++++++++++++++-- .../net/minestom/server/item/ItemStack.java | 51 +++++------- 2 files changed, 93 insertions(+), 37 deletions(-) diff --git a/src/main/java/net/minestom/server/entity/pathfinding/PFPathingEntity.java b/src/main/java/net/minestom/server/entity/pathfinding/PFPathingEntity.java index 552ab78cf..7d31be767 100644 --- a/src/main/java/net/minestom/server/entity/pathfinding/PFPathingEntity.java +++ b/src/main/java/net/minestom/server/entity/pathfinding/PFPathingEntity.java @@ -13,6 +13,15 @@ public class PFPathingEntity implements IPathingEntity { private float searchRange; private Position targetPosition; + // Capacities + private boolean fireResistant; + private boolean cautious; + private boolean climber; + private boolean swimmer; + private boolean aquaphobic; + private boolean avoidsDoorways; + private boolean opensDoors; + public PFPathingEntity(EntityCreature entity) { this.entity = entity; this.searchRange = entity.getAttributeValue(Attribute.FOLLOW_RANGE); @@ -41,6 +50,62 @@ public class PFPathingEntity implements IPathingEntity { this.searchRange = searchRange; } + public boolean isFireResistant() { + return fireResistant; + } + + public void setFireResistant(boolean fireResistant) { + this.fireResistant = fireResistant; + } + + public boolean isCautious() { + return cautious; + } + + public void setCautious(boolean cautious) { + this.cautious = cautious; + } + + public boolean isClimber() { + return climber; + } + + public void setClimber(boolean climber) { + this.climber = climber; + } + + public boolean isSwimmer() { + return swimmer; + } + + public void setSwimmer(boolean swimmer) { + this.swimmer = swimmer; + } + + public boolean isAquaphobic() { + return aquaphobic; + } + + public void setAquaphobic(boolean aquaphobic) { + this.aquaphobic = aquaphobic; + } + + public boolean isAvoidsDoorways() { + return avoidsDoorways; + } + + public void setAvoidsDoorways(boolean avoidsDoorways) { + this.avoidsDoorways = avoidsDoorways; + } + + public boolean isOpensDoors() { + return opensDoors; + } + + public void setOpensDoors(boolean opensDoors) { + this.opensDoors = opensDoors; + } + @Override public Capabilities capabilities() { return new Capabilities() { @@ -51,37 +116,37 @@ public class PFPathingEntity implements IPathingEntity { @Override public boolean fireResistant() { - return false; + return fireResistant; } @Override public boolean cautious() { - return false; + return cautious; } @Override public boolean climber() { - return true; + return climber; } @Override public boolean swimmer() { - return true; + return swimmer; } @Override public boolean aquaphobic() { - return false; + return aquaphobic; } @Override public boolean avoidsDoorways() { - return false; + return avoidsDoorways; } @Override public boolean opensDoors() { - return false; + return opensDoors; } }; } diff --git a/src/main/java/net/minestom/server/item/ItemStack.java b/src/main/java/net/minestom/server/item/ItemStack.java index d79405498..9cddf7904 100644 --- a/src/main/java/net/minestom/server/item/ItemStack.java +++ b/src/main/java/net/minestom/server/item/ItemStack.java @@ -1,6 +1,5 @@ package net.minestom.server.item; -import com.google.gson.JsonObject; import net.minestom.server.chat.ColoredText; import net.minestom.server.data.Data; import net.minestom.server.data.DataContainer; @@ -65,6 +64,11 @@ public class ItemStack implements DataContainer { this(material, amount, (short) 0); } + /** + * Get a new air item + * + * @return an air item + */ public static ItemStack getAirItem() { return new ItemStack(Material.AIR, (byte) 0); } @@ -145,10 +149,24 @@ public class ItemStack implements DataContainer { } } + /** + * Get the item damage (durability) + * + * @return the item damagel + */ public int getDamage() { return damage; } + /** + * Set the item damage (durability) + * + * @param damage the item damage + */ + public void setDamage(int damage) { + this.damage = damage; + } + /** * Get the item amount *

@@ -173,10 +191,6 @@ public class ItemStack implements DataContainer { this.amount = amount; } - public void setDamage(int damage) { - this.damage = damage; - } - /** * Get the special meta object for this item *

@@ -406,7 +420,7 @@ public class ItemStack implements DataContainer { * @return true if the item has the flag {@code flag}, false otherwise */ public boolean hasItemFlag(ItemFlag flag) { - int bitModifier = getBitModifier(flag); + final int bitModifier = getBitModifier(flag); return (this.hideFlag & bitModifier) == bitModifier; } @@ -520,7 +534,7 @@ public class ItemStack implements DataContainer { * @throws NullPointerException if {@code stackingRule} is null */ public void setStackingRule(StackingRule stackingRule) { - Check.notNull(stackingRule, "StackingRule cannot be null!"); + Check.notNull(stackingRule, "The stacking rule cannot be null!"); this.stackingRule = stackingRule; } @@ -543,29 +557,6 @@ public class ItemStack implements DataContainer { return (byte) (1 << hideFlag.ordinal()); } - /** - * Convert the item into a readable Json object - *

- * Mainly used to show an item in a message hover - * - * @return a {@link JsonObject} containing the item data - */ - public synchronized JsonObject toJsonObject() { - JsonObject object = new JsonObject(); - object.addProperty("id", material.getId()); - object.addProperty("Damage", getDamage()); - object.addProperty("Count", getAmount()); - - if (hasDisplayName() || hasLore()) { - JsonObject tagObject = new JsonObject(); - if (hasDisplayName()) { - tagObject.addProperty("display", getDisplayName().toString()); - } - } - - return object; - } - /** * Find the item meta based on the material type *