Skip to content

Commit

Permalink
Move armor type to super class and implement protection value and arm…
Browse files Browse the repository at this point in the history
…or type in vanilla custom registry
  • Loading branch information
eclipseisoffline committed May 10, 2024
1 parent 97e1beb commit 965d11c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -244,6 +251,8 @@ interface Builder {

Builder toolTier(@Nullable String toolTier);

Builder armorType(@Nullable String armorType);

Builder protectionValue(int protectionValue);

Builder translationString(@Nullable String translationString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -98,8 +91,6 @@ interface Builder extends CustomItemData.Builder {

Builder javaId(@NonNegative int javaId);

Builder armorType(@Nullable String armorType);

Builder repairMaterials(@Nullable Set<String> repairMaterials);

Builder hat(boolean isHat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.Objects;
import java.util.OptionalInt;
import java.util.Set;
import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData;

@EqualsAndHashCode
@ToString
Expand All @@ -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;
Expand All @@ -82,6 +82,7 @@ public GeyserCustomItemData(Builder builder) {
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;
Expand Down Expand Up @@ -168,6 +169,11 @@ public String toolTier() {
return toolTier;
}

@Override
public @Nullable String armorType() {
return armorType;
}

@Override
public int protectionValue() {
return protectionValue;
Expand Down Expand Up @@ -210,10 +216,10 @@ public static class Builder implements CustomItemData.Builder {
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;

Expand Down Expand Up @@ -313,6 +319,12 @@ public Builder toolTier(@Nullable String toolTier) {
return this;
}

@Override
public Builder armorType(@Nullable String armorType) {
this.armorType = armorType;
return this;
}

@Override
public Builder protectionValue(int protectionValue) {
this.protectionValue = protectionValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
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;
Expand All @@ -51,7 +50,6 @@ public GeyserNonVanillaCustomItemData(Builder builder) {

this.identifier = builder.identifier;
this.javaId = builder.javaId;
this.armorType = builder.armorType;
this.repairMaterials = builder.repairMaterials;
this.isHat = builder.hat;
this.isChargeable = builder.chargeable;
Expand All @@ -68,11 +66,6 @@ public int javaId() {
return javaId;
}

@Override
public @Nullable String armorType() {
return armorType;
}

@Override
public Set<String> repairMaterials() {
return repairMaterials;
Expand All @@ -96,7 +89,6 @@ public String block() {
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;
Expand Down Expand Up @@ -160,12 +152,6 @@ public Builder javaId(int javaId) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,18 @@ private static NbtMapBuilder createComponentNbt(CustomItemData customItemData, I

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) {
Expand Down

0 comments on commit 965d11c

Please sign in to comment.