Implement logic for new vanilla custom item components in custom item registry

This commit is contained in:
Eclipse 2024-05-10 21:08:21 +00:00
parent 9cd847e1e9
commit 97e1bebcbd
No known key found for this signature in database
GPG key ID: 441A0B7FDD01D03A
3 changed files with 33 additions and 10 deletions

View file

@ -118,6 +118,8 @@ public interface CustomItemData {
/** /**
* Gets the stack size of the item. * Gets the stack size of the item.
* *
* Returns 0 if not set. When not set (or 0), takes the Java item stack count when based of a vanilla item, or uses 64 when porting a modded item.
*
* @return the stack size of the item * @return the stack size of the item
*/ */
@NonNegative @NonNegative
@ -126,6 +128,8 @@ public interface CustomItemData {
/** /**
* Gets the max damage of the item. * Gets the max damage of the item.
* *
* Returns -1 if not set. When not set (or below 0), takes the Java item max damage when based of a vanilla item, or uses 0 when porting a modded item.
*
* @return the max damage of the item * @return the max damage of the item
*/ */
int maxDamage(); int maxDamage();
@ -134,6 +138,8 @@ public interface CustomItemData {
* Gets the attack damage of the item. * Gets the attack damage of the item.
* This is purely visual, and only applied to tools * This is purely visual, and only applied to tools
* *
* Returns 0 if not set. When 0, takes the Java item attack damage when based of a vanilla item, or uses 0 when porting a modded item.
*
* @return the attack damage of the item * @return the attack damage of the item
*/ */
int attackDamage(); int attackDamage();

View file

@ -205,8 +205,8 @@ public class GeyserCustomItemData implements CustomItemData {
protected int textureSize = 16; protected int textureSize = 16;
protected CustomRenderOffsets renderOffsets = null; protected CustomRenderOffsets renderOffsets = null;
protected Set<String> tags = new HashSet<>(); protected Set<String> tags = new HashSet<>();
private int stackSize = 64; private int stackSize = 0;
private int maxDamage = 0; private int maxDamage = -1;
private int attackDamage = 0; private int attackDamage = 0;
private String toolType = null; private String toolType = null;
private String toolTier = null; private String toolTier = null;

View file

@ -131,8 +131,8 @@ public class CustomItemRegistryPopulator {
Set<String> repairMaterials = customItemData.repairMaterials(); Set<String> repairMaterials = customItemData.repairMaterials();
Item.Builder itemBuilder = Item.builder() Item.Builder itemBuilder = Item.builder()
.stackSize(customItemData.stackSize()) .stackSize(customItemData.stackSize() == 0 ? 64 : customItemData.stackSize())
.maxDamage(customItemData.maxDamage()); .maxDamage(Math.max(customItemData.maxDamage(), 0));
Item item = new Item(customIdentifier, itemBuilder) { Item item = new Item(customIdentifier, itemBuilder) {
@Override @Override
public boolean isValidRepairItem(Item other) { public boolean isValidRepairItem(Item other) {
@ -168,12 +168,24 @@ public class CustomItemRegistryPopulator {
NbtMapBuilder itemProperties = NbtMap.builder(); NbtMapBuilder itemProperties = NbtMap.builder();
NbtMapBuilder componentBuilder = NbtMap.builder(); NbtMapBuilder componentBuilder = NbtMap.builder();
setupBasicItemInfo(javaItem.maxDamage(), javaItem.maxStackSize(), mapping.getToolType() != null || customItemData.displayHandheld(), customItemData, itemProperties, componentBuilder, protocolVersion); setupBasicItemInfo(customItemData.maxDamage() < 0 ? javaItem.maxDamage() : customItemData.maxDamage(),
customItemData.stackSize() == 0 ? javaItem.maxStackSize() : customItemData.stackSize(),
mapping.getToolType() != null || customItemData.displayHandheld(),
customItemData, itemProperties, componentBuilder, protocolVersion);
boolean canDestroyInCreative = true; boolean canDestroyInCreative = true;
if (mapping.getToolType() != null) { // This is not using the isTool boolean because it is not just a render type here. String toolType = null;
canDestroyInCreative = computeToolProperties(mapping.getToolType(), itemProperties, componentBuilder, javaItem.attackDamage()); if (mapping.getToolType() != null) {
toolType = mapping.getToolType();
} else if (customItemData.toolType() != null) {
toolType = customItemData.toolType();
} }
if (toolType != null) {
canDestroyInCreative = computeToolProperties(toolType, itemProperties, componentBuilder,
customItemData.attackDamage() == 0 ? javaItem.attackDamage() : customItemData.attackDamage());
}
itemProperties.putBoolean("can_destroy_in_creative", canDestroyInCreative); itemProperties.putBoolean("can_destroy_in_creative", canDestroyInCreative);
if (mapping.getArmorType() != null) { if (mapping.getArmorType() != null) {
@ -184,14 +196,18 @@ public class CustomItemRegistryPopulator {
computeBlockItemProperties(mapping.getBedrockIdentifier(), componentBuilder); computeBlockItemProperties(mapping.getBedrockIdentifier(), componentBuilder);
} }
if (mapping.isEdible()) { if (mapping.isEdible() || customItemData.isEdible()) {
computeConsumableProperties(itemProperties, componentBuilder, 1, false); computeConsumableProperties(itemProperties, componentBuilder, 1, customItemData.canAlwaysEat());
} }
if (mapping.isEntityPlacer()) { if (mapping.isEntityPlacer()) {
computeEntityPlacerProperties(componentBuilder); computeEntityPlacerProperties(componentBuilder);
} }
if (customItemData.isFoil()) {
itemProperties.putBoolean("foil", true);
}
switch (mapping.getBedrockIdentifier()) { switch (mapping.getBedrockIdentifier()) {
case "minecraft:fire_charge", "minecraft:flint_and_steel" -> computeBlockItemProperties("minecraft:fire", componentBuilder); case "minecraft:fire_charge", "minecraft:flint_and_steel" -> computeBlockItemProperties("minecraft:fire", componentBuilder);
case "minecraft:bow", "minecraft:crossbow", "minecraft:trident" -> computeChargeableProperties(itemProperties, componentBuilder, mapping.getBedrockIdentifier(), protocolVersion); case "minecraft:bow", "minecraft:crossbow", "minecraft:trident" -> computeChargeableProperties(itemProperties, componentBuilder, mapping.getBedrockIdentifier(), protocolVersion);
@ -217,7 +233,8 @@ public class CustomItemRegistryPopulator {
NbtMapBuilder itemProperties = NbtMap.builder(); NbtMapBuilder itemProperties = NbtMap.builder();
NbtMapBuilder componentBuilder = NbtMap.builder(); NbtMapBuilder componentBuilder = NbtMap.builder();
setupBasicItemInfo(customItemData.maxDamage(), customItemData.stackSize(), displayHandheld, customItemData, itemProperties, componentBuilder, protocolVersion); setupBasicItemInfo(Math.max(customItemData.maxDamage(), 0), customItemData.stackSize() == 0 ? 64 : customItemData.stackSize(),
displayHandheld, customItemData, itemProperties, componentBuilder, protocolVersion);
boolean canDestroyInCreative = true; boolean canDestroyInCreative = true;
if (customItemData.toolType() != null) { // This is not using the isTool boolean because it is not just a render type here. if (customItemData.toolType() != null) { // This is not using the isTool boolean because it is not just a render type here.