Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-09-08 20:43:04 +02:00
Implement logic for new vanilla custom item components in custom item registry
Dieser Commit ist enthalten in:
Ursprung
9cd847e1e9
Commit
97e1bebcbd
@ -118,6 +118,8 @@ public interface CustomItemData {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@NonNegative
|
||||
@ -126,6 +128,8 @@ public interface CustomItemData {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
int maxDamage();
|
||||
@ -134,6 +138,8 @@ public interface CustomItemData {
|
||||
* Gets the attack damage of the item.
|
||||
* 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
|
||||
*/
|
||||
int attackDamage();
|
||||
|
@ -205,8 +205,8 @@ public class GeyserCustomItemData implements CustomItemData {
|
||||
protected int textureSize = 16;
|
||||
protected CustomRenderOffsets renderOffsets = null;
|
||||
protected Set<String> tags = new HashSet<>();
|
||||
private int stackSize = 64;
|
||||
private int maxDamage = 0;
|
||||
private int stackSize = 0;
|
||||
private int maxDamage = -1;
|
||||
private int attackDamage = 0;
|
||||
private String toolType = null;
|
||||
private String toolTier = null;
|
||||
|
@ -131,8 +131,8 @@ public class CustomItemRegistryPopulator {
|
||||
Set<String> repairMaterials = customItemData.repairMaterials();
|
||||
|
||||
Item.Builder itemBuilder = Item.builder()
|
||||
.stackSize(customItemData.stackSize())
|
||||
.maxDamage(customItemData.maxDamage());
|
||||
.stackSize(customItemData.stackSize() == 0 ? 64 : customItemData.stackSize())
|
||||
.maxDamage(Math.max(customItemData.maxDamage(), 0));
|
||||
Item item = new Item(customIdentifier, itemBuilder) {
|
||||
@Override
|
||||
public boolean isValidRepairItem(Item other) {
|
||||
@ -168,12 +168,24 @@ public class CustomItemRegistryPopulator {
|
||||
NbtMapBuilder itemProperties = 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;
|
||||
if (mapping.getToolType() != null) { // This is not using the isTool boolean because it is not just a render type here.
|
||||
canDestroyInCreative = computeToolProperties(mapping.getToolType(), itemProperties, componentBuilder, javaItem.attackDamage());
|
||||
String toolType = null;
|
||||
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);
|
||||
|
||||
if (mapping.getArmorType() != null) {
|
||||
@ -184,14 +196,18 @@ public class CustomItemRegistryPopulator {
|
||||
computeBlockItemProperties(mapping.getBedrockIdentifier(), componentBuilder);
|
||||
}
|
||||
|
||||
if (mapping.isEdible()) {
|
||||
computeConsumableProperties(itemProperties, componentBuilder, 1, false);
|
||||
if (mapping.isEdible() || customItemData.isEdible()) {
|
||||
computeConsumableProperties(itemProperties, componentBuilder, 1, customItemData.canAlwaysEat());
|
||||
}
|
||||
|
||||
if (mapping.isEntityPlacer()) {
|
||||
computeEntityPlacerProperties(componentBuilder);
|
||||
}
|
||||
|
||||
if (customItemData.isFoil()) {
|
||||
itemProperties.putBoolean("foil", true);
|
||||
}
|
||||
|
||||
switch (mapping.getBedrockIdentifier()) {
|
||||
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);
|
||||
@ -217,7 +233,8 @@ public class CustomItemRegistryPopulator {
|
||||
NbtMapBuilder itemProperties = 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;
|
||||
if (customItemData.toolType() != null) { // This is not using the isTool boolean because it is not just a render type here.
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren