Structure and Overview
PlayerEx includes an API package, located at com.github.clevernucleus.playerex.api and contains the following:
📂api
┣📂client
┃ ┣📄ClientUtil.java class
┃ ┣📄PageLayer.java class
┃ ┣📄PageRegistry.java class
┃ ┗📄RenderComponent.java class
┃
┣📂damage
┃ ┣📄DamageFunction.java interface
┃ ┗📄DamagePredicate.java interface
┃
┣📂event
┃ ┣📄LivingEntityEvents.java class
┃ ┗📄PlayerEntityEvents.java class
┃
┣📄EntityAttributeSupplier.java class
┣📄ExAPI.java class
┣📄ExConfig.java interface
┣📄PacketType.java enum
┗📄PlayerData.java interface
The PlayerEx API can be split into four distinct sub-systems: the client-side page/tab registry, which exists to allow developers to add more inventory tabs and content to existing inventory pages; the damage-registry, which exists to allow developers to register damage handlers to better manipulate damage events; the LivingEntityEvents and PlayerEntityEvents classes, which provide developers useful hooks into attributes and specific methods; and finally, the attribute registry - which acts to provide developers with attribute suppliers and access to all the attributes PlayerEx adds.
API Content
The following subsections detail every method/field in each java class located in the api package.
1. client.ClientUtil.java
| Modifiers and Type | Method/Field and Description |
|---|---|
publicstaticfinalDecimalFormat |
FORMATTING_2 Format for two decimal places. |
publicstaticfinalDecimalFormat |
FORMATTING_3 Format for three decimal places. |
publicstaticdouble |
displayValue(Supplier<EntityAttribute> attribute, double value) Takes the input attribute and looks for the PERCENTAGE_PROPERTY property; if it is present, multiplies the input value by the property’s multiplier. If not, then looks for the MULTIPLIER_PROPERTY property; if present, multiplies the input value by the property’s multiplier. Else returns the input value. |
publicstaticString |
formatValue(Supplier<EntityAttribute> attribute, double value) If the input value is positive, adds the + prefix. If the input attribute has the PERCENTAGE_PROPERTY property, appends the % suffix. |
publicstaticvoid |
appendChildrenToTooltip(List<Text> tooltip, Supplier<EntityAttribute> attribute) Looks for the input attribute’s functions, and if there are any, formats them and adds them to the input list as tooltips. |
publicstaticvoid |
modifyAttributes(PacketType type, Consumer<BiConsumer<EntityAttributeSupplier, Double>> … consumers) Client-side. Sends a packet to the server to modify the attribute modifiers provided by PlayerEx by the input amount, and performs the checks and functions dictated by the PacketType (this logic is run on the server when it receives the packet). |
2. client.PageLayer.java
| Modifiers and Type | Method/Field and Description |
|---|---|
protectedfinalHandledScreen<?> |
parent Reference to the parent screen. |
publicvoid |
render(MatrixStack matrices, int mouseX, int mouseY, float delta) This is where text and tooltips can be rendered, in that order. |
publicvoid |
drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) This is where textures and widgets can be rendered, in that order. |
3. client.PageRegistry.java
| Modifiers and Type | Method/Field and Description |
|---|---|
publicstaticvoid |
registerPage(Identifier pageId, Identifier icon, Identifier texture, Text title) Registers a page and tab to the PlayerEx screen. |
publicstaticvoid |
registerPage(Identifier pageId, Identifier icon, Text title) Registers a page and tab to the PlayerEx screen, but with the default background. |
publicstaticvoid |
registerLayer(Identifier pageId, PageLayer.Builder builder) Registers a page layer to a page of the same input pageId. |
4. client.RenderComponent.java
| Modifiers and Type | Method/Field and Description |
|---|---|
publicstaticRenderComponent |
of(Supplier<EntityAttribute> attribute, Function<LivingEntity, Text> function, Function<LivingEntity, List<Text>> tooltip, int dx, int dy) Creates a new RenderComponent object. |
publicstaticRenderComponent |
of(Function<LivingEntity, Text> function, Function<LivingEntity, List<Text>> tooltip, int dx, int dy) Creates a new RenderComponent object. |
privateboolean |
isMouseOver(float x, float y, float width, float height, int mouseX, int mouseY) Checks to see if the mouse is over the input area. |
publicvoid |
renderText(LivingEntity livingEntity, MatrixStack matrices, TextRenderer textRenderer, int x, int y, float scaleX, float scaleY) Renders the text from the input function. |
publicvoid |
renderTooltip(LivingEntity livingEntity, RenderTooltip consumer, MatrixStack matrices, TextRenderer textRenderer, int x, int y, int mouseX, int mouseY, float scaleX, float scaleY) Renders tooltip for the given text. |
5. damage.DamageFunction.java
| Modifiers and Type | Method/Field and Description |
|---|---|
float |
apply(LivingEntity livingEntity, DamageSource source, float damage) Using the input conditions, modifies the incoming damage (either reducing or increasing it) and returns the result. |
6. damage.DamagePredicate.java
| Modifiers and Type | Method/Field and Description |
|---|---|
boolean |
test(LivingEntity livingEntity, DamageSource source, float damage) Determines, using the input conditions, whether to apply the DamageFunction to the incoming damage of the LivingEntity. |
7. event.LivingEntityEvents.java
| Modifiers and Type | Method/Field and Description |
|---|---|
publicstaticfinalEvent<Healed> |
ON_HEAL Fired before LivingEntity#heal; allows the amount healed to be modified before healing happens. Setting the output to 0 is an unreliable way to negate incoming damage depending on other mods installed. Instead, use SHOULD_HEAL. |
publicstaticfinalEvent<Heal> |
SHOULD_HEAL Fired at the start of LivingEntity#heal, but before healing is applied. Can return false to cancel all healing, or true to allow it. |
publicstaticfinalEvent<Tick> |
EVERY_SECOND Fired once at the end of LivingEntity#tick, every 20 ticks (1 second). |
publicstaticfinalEvent<Damaged> |
ON_DAMAGE Fired before LivingEntity#damage; allows the amount of damage to be modified before it is used in any way. Can be used to perform logic prior to the damage method, and can return the original damage to avoid modifying the value. The original value is the incoming damage, followed by the result of this event by any previous registries. Setting the output to 0 is an unreliable way to negate incoming damage depending on other mods installed. Instead, use SHOULD_DAMAGE. |
publicstaticfinalEvent<Damage> |
SHOULD_DAMAGE Fired after: LivingEntity#isInvulnerableToWorld#isClientLivingEntity#isDeadDamageSource#isFire and LivingEntity#hasStatusEffectLivingEntity#isSleepingbut before all other logic is performed. Can be used to cancel the method and prevent damage from being taken by returning false. Returning true allows the logic to continue. |
publicinterface |
Healed {…} Nested functional interface for ON_HEAL . |
publicinterface |
Heal {…} Nested functional interface for SHOULD_HEAL . |
publicinterface |
Tick {…} Nested functional interface for EVERY_SECOND . |
publicinterface |
Damaged {…} Nested functional interface for ON_DAMAGE . |
publicinterface |
Damage {…} Nested functional interface for SHOULD_DAMAGE . |
8. event.PlayerEntityEvents.java
| Modifiers and Type | Method/Field and Description |
|---|---|
publicstaticfinalEvent<AttackCritDamage> |
ON_CRIT Fired after the player lands a critical hit. The result is the damage. |
publicstaticfinalEvent<AttackCritBoolean> |
SHOULD_CRIT Fired when determining if the player’s attack is critical. Return true if it is critical, return false if it is not. |
publicinterface |
AttackCritDamage {…} Nested functional interface for ON_DAMAGE . |
publicinterface |
AttackCritBoolean {…} Nested functional interface for SHOULD_DAMAGE . |
9. EntityAttributeSupplier.java
| Modifiers and Type | Method/Field and Description |
|---|---|
privatefinalIdentifier |
identifier The attribute’s identifier (data does not change, objects do). |
publicstaticEntityAttributeSupplier |
of(Identifier registryKey) Creates a new EntityAttributeSupplier object. |
publicIdentifier |
getId() Returns the supplier’s attribute registry key. |
publicEntityAttribute |
get() Returns the mapped EntityAttribute object in the games attribute registry if it exists for this supplier’s registry key; otherwise, returns null. |
10. ExAPI.java
| Modifiers and Type | Method/Field and Description |
|---|---|
publicstaticfinalString |
MODID The PlayerEx mod id. |
publicstaticfinalString |
INTEGER_PROPERTY Round value to integer property that is attached to some attributes. |
publicstaticfinalString |
PERCENTAGE_PROPERTY Multiply value by property and append % symbol. |
publicstaticfinalString |
MULTIPLY_PROPERTY Multiply value by property. |
publicstaticfinalUUID |
PLAYEREX_MODIFIER_ID The UUID PlayerEx attribute modifiers use. |
publicstaticfinalCacheableValue<Integer> |
LEVEL_VALUE The CacheableValue key for PlayerEx’s player data.. |
publicstaticfinalComponentKey<PlayerData> |
PLAYER_DATA The Caridnal Components Key for PlayerEx player data. |
publicstaticfinalEntityAttributeSupplier |
LEVEL The level attribute. |
publicstaticfinalEntityAttributeSupplier |
CONSTITUTION The constitution attribute. |
publicstaticfinalEntityAttributeSupplier |
STRENGTH The strength attribute. |
publicstaticfinalEntityAttributeSupplier |
DEXTERITY The dexterity attribute. |
publicstaticfinalEntityAttributeSupplier |
INTELLIGENCE The intelligence attribute. |
publicstaticfinalEntityAttributeSupplier |
LUCKINESS The luckiness attribute. |
publicstaticfinalEntityAttributeSupplier |
EVASION The evasion attribute. |
publicstaticfinalEntityAttributeSupplier |
LIFESTEAL The lifesteal attribute. |
publicstaticfinalEntityAttributeSupplier |
HEALTH_REGENERATION The health regeneration attribute. |
publicstaticfinalEntityAttributeSupplier |
HEAL_AMPLIFICATION The heal amplification attribute. |
publicstaticfinalEntityAttributeSupplier |
MELEE_CRIT_DAMAGE The melee crit damage attribute. |
publicstaticfinalEntityAttributeSupplier |
MELEE_CRIT_CHANCE The melee crit chance attribute. |
publicstaticfinalEntityAttributeSupplier |
RANGED_CRIT_DAMAGE The ranged crit damage attribute. |
publicstaticfinalEntityAttributeSupplier |
RANGED_CRIT_CHANCE The ranged crit chance attribute. |
publicstaticfinalEntityAttributeSupplier |
RANGED_DAMAGE The ranged damage attribute. |
publicstaticfinalEntityAttributeSupplier |
FIRE_RESISTANCE The fire resistance attribute. |
publicstaticfinalEntityAttributeSupplier |
FREEZE_RESISTANCE The freeze resistance attribute. |
publicstaticfinalEntityAttributeSupplier |
LIGHTNING_RESISTANCE The lightning resistance attribute. |
publicstaticfinalEntityAttributeSupplier |
POISON_RESISTANCE The poison resistance attribute. |
publicstaticfinalEntityAttributeSupplier |
WITHER_RESISTANCE The wither resistance attribute. |
publicstaticfinalEntityAttributeSupplier |
BREAKING_SPEED The breaking speed attribute. |
publicstaticfinalEntityAttributeSupplier |
REACH_DISTANCE The reach distance attribute. This is not implemented by PlayerEx, but by JamieWhiteShirt’s reach-entity-attributes. |
publicstaticfinalEntityAttributeSupplier |
ATTACK_RANGE The attack range attribute. This is not implemented by PlayerEx, but by JamieWhiteShirt’s reach-entity-attributes. |
publicstaticExConfig |
getConfig() Access to PlayerEx’s config. |
publicstaticvoid |
registerDamageModification(DamagePredicate predicate, DamageFunction function) Registers a damage modification condition that is applied to living entities under specific circumstances. |
publicstaticvoid |
registerRefundCondition(BiFunction<PlayerData, PlayerEntity> refundCondition) Registers a refund condition. Refund conditions tell the game what can be refunded and what the maximum number of refund points are for a given circumstance. |
11. ExConfig.java
| Modifiers and Type | Method/Field and Description |
|---|---|
boolean |
resetOnDeath() |
boolean |
isAttributesGuiDisabled() |
int |
skillPointsPerLevelUp() |
int |
requiredXp(PlayerEntity player) |
float |
levelUpVolume() |
float |
skillUpVolume() |
float |
textScaleX() |
float |
textScaleY() |
12. PacketType.java
| Modifiers and Type | Method/Field and Description |
|---|---|
publicstaticfinalPacketType |
DEFAULT Does nothing extra - just allows the server to modify PlayerEx’s attribute modifiers. |
publicstaticfinalPacketType |
LEVEL Only allows modification if the player’s experience levels are greater than or equal to the required xp to level up. Also removes those experience levels from the player and adds n skill points; where n is defined by config option skill points per level up. |
publicstaticfinalPacketType |
SKILL Only allows modification if the player’s skill points are greater than or equal to 1. Also subtracts one skill point from the player. |
publicstaticfinalPacketType |
REFUND Only allows modification if the player’s refund points are greater than or equal to 1. Also subtracts one refund point and adds one skill point. |
publicstaticPacketType |
fromId(byte id) Gets the correct PacketType from the input (or else DEFAULT). |
publicbyte |
id() Returns the PacketType’s id. |
publicboolean |
test(MinecraftServer server, ServerPlayerEntity player, PlayerData data) Runs the test function. |