Move armor type to super class and implement protection value and armor type in vanilla custom registry

This commit is contained in:
Eclipse 2024-05-10 21:23:46 +00:00
parent 97e1bebcbd
commit 965d11c7a1
No known key found for this signature in database
GPG Key ID: 441A0B7FDD01D03A
5 changed files with 34 additions and 26 deletions

View File

@ -165,6 +165,13 @@ public interface CustomItemData {
*/
@Nullable String translationString();
/**
* Gets the armor type of the item.
*
* @return the armor type of the item
*/
@Nullable String armorType();
/**
* Gets the armor protection value of the item.
*
@ -244,6 +251,8 @@ public interface CustomItemData {
Builder toolTier(@Nullable String toolTier);
Builder armorType(@Nullable String armorType);
Builder protectionValue(int protectionValue);
Builder translationString(@Nullable String translationString);

View File

@ -50,13 +50,6 @@ public interface NonVanillaCustomItemData extends CustomItemData {
*/
@NonNegative int javaId();
/**
* Gets the armor type of the item.
*
* @return the armor type of the item
*/
@Nullable String armorType();
/**
* Gets the repair materials of the item.
*
@ -98,8 +91,6 @@ public interface NonVanillaCustomItemData extends CustomItemData {
Builder javaId(@NonNegative int javaId);
Builder armorType(@Nullable String armorType);
Builder repairMaterials(@Nullable Set<String> repairMaterials);
Builder hat(boolean isHat);

View File

@ -37,7 +37,6 @@ import java.util.HashSet;
import java.util.Objects;
import java.util.OptionalInt;
import java.util.Set;
import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData;
@EqualsAndHashCode
@ToString
@ -59,6 +58,7 @@ public class GeyserCustomItemData implements CustomItemData {
private final String toolType;
private final String toolTier;
private final String translationString;
private final String armorType;
private final int protectionValue;
private final boolean isFoil;
private final boolean isEdible;
@ -82,6 +82,7 @@ public class GeyserCustomItemData implements CustomItemData {
this.toolType = builder.toolType;
this.toolTier = builder.toolTier;
this.translationString = builder.translationString;
this.armorType = builder.armorType;
this.protectionValue = builder.protectionValue;
this.isFoil = builder.foil;
this.isEdible = builder.edible;
@ -168,6 +169,11 @@ public class GeyserCustomItemData implements CustomItemData {
return toolTier;
}
@Override
public @Nullable String armorType() {
return armorType;
}
@Override
public int protectionValue() {
return protectionValue;
@ -210,10 +216,10 @@ public class GeyserCustomItemData implements CustomItemData {
private int attackDamage = 0;
private String toolType = null;
private String toolTier = null;
private String armorType = null;
private int protectionValue = 0;
private String translationString;
private boolean foil = false;
private boolean tool = false;
private boolean edible = false;
private boolean canAlwaysEat = false;
@ -313,6 +319,12 @@ public class GeyserCustomItemData implements CustomItemData {
return this;
}
@Override
public Builder armorType(@Nullable String armorType) {
this.armorType = armorType;
return this;
}
@Override
public Builder protectionValue(int protectionValue) {
this.protectionValue = protectionValue;

View File

@ -40,7 +40,6 @@ import java.util.Set;
public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData implements NonVanillaCustomItemData {
private final String identifier;
private final int javaId;
private final String armorType;
private final Set<String> repairMaterials;
private final boolean isHat;
private final boolean isChargeable;
@ -51,7 +50,6 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
this.identifier = builder.identifier;
this.javaId = builder.javaId;
this.armorType = builder.armorType;
this.repairMaterials = builder.repairMaterials;
this.isHat = builder.hat;
this.isChargeable = builder.chargeable;
@ -68,11 +66,6 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
return javaId;
}
@Override
public @Nullable String armorType() {
return armorType;
}
@Override
public Set<String> repairMaterials() {
return repairMaterials;
@ -96,7 +89,6 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
public static class Builder extends GeyserCustomItemData.Builder implements NonVanillaCustomItemData.Builder {
private String identifier = null;
private int javaId = -1;
private String armorType = null;
private Set<String> repairMaterials;
private boolean hat = false;
private boolean chargeable = false;
@ -160,12 +152,6 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i
return this;
}
@Override
public Builder armorType(@Nullable String armorType) {
this.armorType = armorType;
return this;
}
@Override
public Builder repairMaterials(@Nullable Set<String> repairMaterials) {
this.repairMaterials = repairMaterials;

View File

@ -188,8 +188,18 @@ public class CustomItemRegistryPopulator {
itemProperties.putBoolean("can_destroy_in_creative", canDestroyInCreative);
String armorType = null;
int protectionValue = 0;
if (mapping.getArmorType() != null) {
computeArmorProperties(mapping.getArmorType(), mapping.getProtectionValue(), itemProperties, componentBuilder);
armorType = mapping.getArmorType();
protectionValue = mapping.getProtectionValue();
} else if (customItemData.armorType() != null) {
armorType = customItemData.armorType();
protectionValue = customItemData.protectionValue();
}
if (armorType != null) {
computeArmorProperties(armorType, protectionValue, itemProperties, componentBuilder);
}
if (mapping.getFirstBlockRuntimeId() != null) {