-
-
Notifications
You must be signed in to change notification settings - Fork 5
Arrow Properties
NOTE: This topic assumes a basic understanding of the Java programming language. Basic concepts will not be reviewed
Unlike in AlchemicalArrows 2 where a few methods had to be overridden to define unique, single-value properties of an arrow, AlchemicalArrows 3 gives developers access to a much more powerful and flexible system, arrow properties. These properties may be applied to custom AlchemicalArrow
implementations to give it unique characteristics and qualities. By default, AlchemicalArrows provides three properties that may be used by custom arrows, although the creation of custom properties is also possible and allows developers to create unique properties handled by external plugins. This topic will be covered in a later wiki page.
Here, the three default properties and how to set them will be covered with the example used in the Creating a Custom Alchemical Arrow page, the Cake Arrow. It is recommended that this page is read if the code provided is not understood.
Before being able to set properties for arrows, the use of an arrow's PropertyMap should be explained. Each implementation of AlchemicalArrow
will have a protected field named properties
of type PropertyMap
, a class provided by the AlchemicalArrows API. It is with this field that properties may be set. Because this field is protected, it may be accessed by calling either super.properties
or this.properties
.
ArrowProperty
is a class added in AlchemicalArrows 3 that specifies a single-value property type. While this object does not necessarily hold data itself, it acts as a unique key (and in fact, is a Keyed object) and may be used to create custom properties. See Custom Arrow Properties for more information on how to take advantage of custom properties. For our purposes, we really only care about the default properties, all of which are listed as constants in the ArrowProperty
class. They are as follows:
Defined by ArrowProperty#SKELETONS_CAN_SHOOT
A property of type boolean
that defines whether skeletons are capable of shooting the alchemical arrow. If true
, the arrow will be shot randomly by skeletons. If false
, it will not be part of the skeleton's arsenal. This property's default value is true
.
Defined by ArrowProperty#ALLOW_INFINITY
A property of type boolean
that defines whether players are permitted to use the alchemical arrow with the infinity bow enchantment. If true
, alchemical arrows shot with the infinity enchantment will not decrease in count as usual. If false
, the arrow will be shot as if the infinity enchantment were ignored. This property's default value is false
Defined by ArrowProperty#SKELETON_LOOT_WEIGHT
A property of type double
that defines the weighted chance that a skeleton may drop this arrow as loot in place of a regular arrow. If this property is set to 0.0
, it is impossible for skeletons to drop the alchemical arrow. This property's default value is 10.0
Let's return to our Cake Arrow created in the Creating a Custom Arrow wiki page (see above for reference). As mentioned above in the The PropertyMap section, each implementation of AlchemicalArrow
has a protected properties
field in which arrow properties are held. To set a value, it's as easy as obtaining the map and updating its values with #setProperty(ArrowProperty<T>, T)
. The use of generics restricts the type to be passed to the method (i.e. a property of type boolean
would have no use for a double
value).
Let's go ahead and set some properties for our Cake Arrow. This is something that should be done in the constructor.
public class AlchemicalArrowCake extends AlchemicalArrow {
private final NamespacedKey key;
private final ItemStack item;
public AlchemicalArrowCake(AlchemicalArrows plugin) {
this.key = new NamespacedKey(plugin, "cake");
this.item = new ItemStack(Material.ARROW);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Cake Arrow");
this.item.setItemMeta(meta);
// Update properties
this.properties.setProperty(ArrowProperty.ALLOW_INFINITY, true);
this.properties.setProperty(ArrowProperty.SKELETON_LOOT_WEIGHT, 100.0);
}
@Override
public NamespacedKey getKey() {
return key;
}
@Override
public String getDisplayName() {
return ChatColor.LIGHT_PURPLE + "Cake Arrow";
}
@Override
public ItemStack getItem() {
return item.clone();
}
}
That's it! Now our cake arrow may be shot an infinite amount of times with the infinity enchantment and skeletons have a massive chance to drop cake arrows over any other arrow. Because the default value of the alchemicalarrows:skeletons_can_shoot
property is true, we need not modify this unless we need to set it to false. This process would be similar if a custom property were defined.
It should, however, be noted that if a custom property is defined by an external plugin (i.e. one not defined by AlchemicalArrows or the plugin handling the cake arrow), you will have to also depend on that plugin and retrieve an instance of that property some other way. How that property is obtained depends entirely on the developer of the plugin creating the properties, but you need not worry about that for the sake of this basic wiki on how to set properties.
Of course, now we have all our properties defined for our cake arrow, but it's still rather useless beyond being dropped by skeletons a lot and being shot using the infinity enchantment. While all our changes have been rather minor so far, the following tutorials will get much more interesting as we finally add proper in-world content for our arrow.