mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Return -1 if not set for attack damage and protection value and implement proper fallbacks
This commit is contained in:
parent
db92184d42
commit
5b864ab88e
3 changed files with 13 additions and 10 deletions
|
@ -142,11 +142,11 @@ public interface CustomItemData {
|
|||
* Gets the attack damage of the item.
|
||||
* This is purely visual, and only applied to tools
|
||||
*
|
||||
* <p>Returns 0 if not set. When 0, Geyser takes the Java item attack damage when based on a vanilla item, or uses 0 when porting a modded item.</p>
|
||||
* <p>Returns -1 if not set. When not set, Geyser takes the Java item attack damage when based on a vanilla item, or uses 0 when porting a modded item.</p>
|
||||
*
|
||||
* @return the attack damage of the item
|
||||
*/
|
||||
@NonNegative int attackDamage();
|
||||
int attackDamage();
|
||||
|
||||
/**
|
||||
* Gets the armor type of the item.
|
||||
|
@ -161,11 +161,13 @@ public interface CustomItemData {
|
|||
/**
|
||||
* Gets the armor protection value of the item.
|
||||
*
|
||||
* <p>Only has a function when {@link CustomItemData#armorType} is set.</p>
|
||||
* <p>Only has a function when {@link CustomItemData#armorType} is set, or when the Java item is an armor item (when based on a vanilla item).</p>
|
||||
*
|
||||
* <p>Returns -1 if not set. When not set, Geyser takes the Java item protection value when based on a vanilla item, or uses 0 when porting a modded item.</p>
|
||||
*
|
||||
* @return the armor protection value of the item
|
||||
*/
|
||||
@NonNegative int protectionValue();
|
||||
int protectionValue();
|
||||
|
||||
/**
|
||||
* Gets if the item is a hat. This is used to determine if the item should be rendered on the player's head, and
|
||||
|
|
|
@ -204,9 +204,9 @@ public class GeyserCustomItemData implements CustomItemData {
|
|||
protected Set<String> tags = new HashSet<>();
|
||||
private int stackSize = 0;
|
||||
private int maxDamage = -1;
|
||||
private int attackDamage = 0;
|
||||
private int attackDamage = -1;
|
||||
private String armorType = null;
|
||||
private int protectionValue = 0;
|
||||
private int protectionValue = -1;
|
||||
private boolean hat = false;
|
||||
private boolean foil = false;
|
||||
private boolean edible = false;
|
||||
|
|
|
@ -182,10 +182,11 @@ public class CustomItemRegistryPopulator {
|
|||
int protectionValue = 0;
|
||||
if (mapping.getArmorType() != null) {
|
||||
armorType = mapping.getArmorType();
|
||||
protectionValue = mapping.getProtectionValue();
|
||||
protectionValue = customItemData.protectionValue() == -1 ? mapping.getProtectionValue() : customItemData.protectionValue();
|
||||
} else if (customItemData.armorType() != null) {
|
||||
armorType = customItemData.armorType();
|
||||
protectionValue = customItemData.protectionValue();
|
||||
// Using 0 as fallback here because the Java item doesn't have an armor type - so its protection value would be 0
|
||||
protectionValue = customItemData.protectionValue() == -1 ? 0 : customItemData.protectionValue();
|
||||
}
|
||||
|
||||
if (armorType != null) {
|
||||
|
@ -244,13 +245,13 @@ public class CustomItemRegistryPopulator {
|
|||
|
||||
boolean canDestroyInCreative = true;
|
||||
if (customItemData.toolType() != null) { // This is not using the isTool boolean because it is not just a render type here.
|
||||
canDestroyInCreative = computeToolProperties(Objects.requireNonNull(customItemData.toolType()), itemProperties, componentBuilder, customItemData.attackDamage());
|
||||
canDestroyInCreative = computeToolProperties(Objects.requireNonNull(customItemData.toolType()), itemProperties, componentBuilder, Math.max(0, customItemData.attackDamage()));
|
||||
}
|
||||
itemProperties.putBoolean("can_destroy_in_creative", canDestroyInCreative);
|
||||
|
||||
String armorType = customItemData.armorType();
|
||||
if (armorType != null) {
|
||||
computeArmorProperties(armorType, customItemData.protectionValue(), itemProperties, componentBuilder);
|
||||
computeArmorProperties(armorType, Math.max(0, customItemData.protectionValue()), itemProperties, componentBuilder);
|
||||
}
|
||||
|
||||
if (customItemData.isEdible()) {
|
||||
|
|
Loading…
Reference in a new issue