Added options for the pathfinder

This commit is contained in:
Felix Cravic 2020-08-12 13:10:57 +02:00
parent 5a6afbbb89
commit 91711401c0
2 changed files with 93 additions and 37 deletions

View File

@ -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;
}
};
}

View File

@ -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
* <p>
@ -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
* <p>
@ -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
* <p>
* 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
*