Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-27 08:30:12 +01:00
Update the item parts
Dieser Commit ist enthalten in:
Ursprung
6d8021f155
Commit
aed7f1bed7
@ -43,11 +43,11 @@ public class CompassItem extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
public ItemData.Builder translateToBedrock(int count, DataComponents components, ItemMapping mapping, ItemMappings mappings) {
|
||||||
if (isLodestoneCompass(itemStack.getDataComponents())) {
|
if (isLodestoneCompass(components)) {
|
||||||
return super.translateToBedrock(itemStack, mappings.getLodestoneCompass(), mappings);
|
return super.translateToBedrock(count, components, mappings.getLodestoneCompass(), mappings);
|
||||||
}
|
}
|
||||||
return super.translateToBedrock(itemStack, mapping, mappings);
|
return super.translateToBedrock(count, components, mapping, mappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,10 +25,8 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import org.cloudburstmc.nbt.NbtMap;
|
|
||||||
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
||||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||||
import org.geysermc.geyser.registry.type.ItemMappings;
|
import org.geysermc.geyser.registry.type.ItemMappings;
|
||||||
@ -39,12 +37,12 @@ public class FilledMapItem extends MapItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
public ItemData.Builder translateToBedrock(int count, DataComponents components, ItemMapping mapping, ItemMappings mappings) {
|
||||||
ItemData.Builder builder = super.translateToBedrock(itemStack, mapping, mappings);
|
ItemData.Builder builder = super.translateToBedrock(count, components, mapping, mappings);
|
||||||
DataComponents components = itemStack.getDataComponents();
|
|
||||||
if (components == null) {
|
if (components == null) {
|
||||||
// This is a fallback for maps with no nbt (Change added back in June 2020; is it needed in 2023?)
|
// This is a fallback for maps with no nbt (Change added back in June 2020; is it needed in 2023?)
|
||||||
return builder.tag(NbtMap.builder().putInt("map", 0).build());
|
//return builder.tag(NbtMap.builder().putInt("map", 0).build()); TODO if this is *still* broken, let's move it to translateComponentsToBedrock
|
||||||
|
return builder;
|
||||||
} else {
|
} else {
|
||||||
Integer mapColor = components.get(DataComponentType.MAP_COLOR);
|
Integer mapColor = components.get(DataComponentType.MAP_COLOR);
|
||||||
if (mapColor != null) {
|
if (mapColor != null) {
|
||||||
|
@ -32,6 +32,7 @@ import com.github.steveice10.opennbt.tag.builtin.*;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.nbt.NbtMap;
|
import org.cloudburstmc.nbt.NbtMap;
|
||||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
|
import org.cloudburstmc.nbt.NbtType;
|
||||||
import org.geysermc.geyser.level.FireworkColor;
|
import org.geysermc.geyser.level.FireworkColor;
|
||||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
@ -63,9 +64,10 @@ public class FireworkRocketItem extends Item {
|
|||||||
}
|
}
|
||||||
List<NbtMap> explosionNbt = new ArrayList<>();
|
List<NbtMap> explosionNbt = new ArrayList<>();
|
||||||
for (Fireworks.FireworkExplosion explosion : explosions) {
|
for (Fireworks.FireworkExplosion explosion : explosions) {
|
||||||
explosionNbt.add(translateExplosionToBedrock(explosion, ""));
|
explosionNbt.add(translateExplosionToBedrock(explosion));
|
||||||
}
|
}
|
||||||
|
fireworksNbt.putList("Explosions", NbtType.COMPOUND, explosionNbt);
|
||||||
|
builder.putCompound("Fireworks", fireworksNbt.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,17 +75,15 @@ public class FireworkRocketItem extends Item {
|
|||||||
super.translateNbtToJava(tag, mapping);
|
super.translateNbtToJava(tag, mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
static NbtMap translateExplosionToBedrock(Fireworks.FireworkExplosion explosion, String newName) {
|
static NbtMap translateExplosionToBedrock(Fireworks.FireworkExplosion explosion) {
|
||||||
NbtMapBuilder newExplosionData = NbtMap.builder();
|
NbtMapBuilder newExplosionData = NbtMap.builder();
|
||||||
|
|
||||||
if (explosion.get("Type") != null) {
|
// if (explosion.get("Type") != null) {
|
||||||
newExplosionData.put(new ByteTag("FireworkType", MathUtils.getNbtByte(explosion.get("Type").getValue())));
|
// newExplosionData.put(new ByteTag("FireworkType", MathUtils.getNbtByte(explosion.get("Type").getValue())));
|
||||||
}
|
// }
|
||||||
//newExplosionData.putByte("FireworkType", explosion.get) //TODO???
|
//newExplosionData.putByte("FireworkType", explosion.get) //TODO???
|
||||||
|
|
||||||
// TODO do we need length checks
|
int[] oldColors = explosion.getColors();
|
||||||
if (explosion.get("Colors") != null) {
|
|
||||||
int[] oldColors = (int[]) explosion.get("Colors").getValue();
|
|
||||||
byte[] colors = new byte[oldColors.length];
|
byte[] colors = new byte[oldColors.length];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -91,20 +91,17 @@ public class FireworkRocketItem extends Item {
|
|||||||
colors[i++] = FireworkColor.fromJavaRGB(color);
|
colors[i++] = FireworkColor.fromJavaRGB(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
newExplosionData.put(new ByteArrayTag("FireworkColor", colors));
|
newExplosionData.putByteArray("FireworkColor", colors);
|
||||||
}
|
|
||||||
|
|
||||||
if (explosion.get("FadeColors") != null) {
|
oldColors = explosion.getFadeColors();
|
||||||
int[] oldColors = (int[]) explosion.get("FadeColors").getValue();
|
colors = new byte[oldColors.length];
|
||||||
byte[] colors = new byte[oldColors.length];
|
|
||||||
|
|
||||||
int i = 0;
|
i = 0;
|
||||||
for (int color : oldColors) {
|
for (int color : oldColors) {
|
||||||
colors[i++] = FireworkColor.fromJavaRGB(color);
|
colors[i++] = FireworkColor.fromJavaRGB(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
newExplosionData.put(new ByteArrayTag("FireworkFade", colors));
|
newExplosionData.putByteArray("FireworkFade", colors);
|
||||||
}
|
|
||||||
|
|
||||||
newExplosionData.putBoolean("FireworkTrail", explosion.isHasTrail());
|
newExplosionData.putBoolean("FireworkTrail", explosion.isHasTrail());
|
||||||
newExplosionData.putBoolean("FireworkFlicker", explosion.isHasTwinkle()); // TODO verify
|
newExplosionData.putBoolean("FireworkFlicker", explosion.isHasTwinkle()); // TODO verify
|
||||||
|
@ -25,12 +25,13 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.Fireworks;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.cloudburstmc.nbt.NbtMap;
|
||||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||||
@ -44,19 +45,15 @@ public class FireworkStarItem extends Item {
|
|||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
Tag explosion = tag.remove("Explosion");
|
Fireworks.FireworkExplosion explosion = components.get(DataComponentType.FIREWORK_EXPLOSION);
|
||||||
if (explosion instanceof CompoundTag) {
|
if (explosion != null) {
|
||||||
CompoundTag newExplosion = FireworkRocketItem.translateExplosionToBedrock((CompoundTag) explosion, "FireworksItem");
|
NbtMap newExplosion = FireworkRocketItem.translateExplosionToBedrock(explosion);
|
||||||
tag.put(newExplosion);
|
builder.putCompound("FireworksItem", newExplosion);
|
||||||
Tag color = ((CompoundTag) explosion).get("Colors");
|
int[] colors = explosion.getColors();
|
||||||
if (color instanceof IntArrayTag) {
|
if (colors.length != 0) {
|
||||||
// Determine the custom color, if any.
|
// Determine the custom color, if any.
|
||||||
// Mostly replicates Java's own rendering code, as Java determines the final firework star color client-side
|
// Mostly replicates Java's own rendering code, as Java determines the final firework star color client-side
|
||||||
// while Bedrock determines it server-side.
|
// while Bedrock determines it server-side.
|
||||||
int[] colors = ((IntArrayTag) color).getValue();
|
|
||||||
if (colors.length == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int finalColor;
|
int finalColor;
|
||||||
if (colors.length == 1) {
|
if (colors.length == 1) {
|
||||||
finalColor = colors[0];
|
finalColor = colors[0];
|
||||||
@ -77,7 +74,7 @@ public class FireworkStarItem extends Item {
|
|||||||
finalColor = r << 16 | g << 8 | b;
|
finalColor = r << 16 | g << 8 | b;
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.put(new IntTag("customColor", finalColor));
|
builder.putInt("customColor", finalColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,6 @@
|
|||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||||
@ -42,11 +40,7 @@ public class FishingRodItem extends Item {
|
|||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
// Fix damage inconsistency
|
// Fix damage inconsistency
|
||||||
Tag damage = tag.get("Damage");
|
builder.getDamage().ifPresent(damage -> builder.setDamage(getBedrockDamage(damage)));
|
||||||
if (damage instanceof IntTag) {
|
|
||||||
int originalDurability = ((IntTag) damage).getValue();
|
|
||||||
tag.put(new IntTag("Damage", getBedrockDamage(originalDurability)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getBedrockDamage(int javaDamage) {
|
public static int getBedrockDamage(int javaDamage) {
|
||||||
|
@ -26,6 +26,9 @@
|
|||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.Instrument;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
||||||
@ -52,10 +55,14 @@ public class GoatHornItem extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
public ItemData.Builder translateToBedrock(int count, DataComponents components, ItemMapping mapping, ItemMappings mappings) {
|
||||||
ItemData.Builder builder = super.translateToBedrock(itemStack, mapping, mappings);
|
ItemData.Builder builder = super.translateToBedrock(count, components, mapping, mappings);
|
||||||
if (itemStack.getNbt() != null && itemStack.getNbt().get("instrument") instanceof StringTag instrumentTag) {
|
if (components == null) {
|
||||||
String instrument = instrumentTag.getValue();
|
return builder;
|
||||||
|
}
|
||||||
|
Instrument instrument = components.get(DataComponentType.INSTRUMENT);
|
||||||
|
// TODO registry
|
||||||
|
if (instrument != null) {
|
||||||
// Drop the Minecraft namespace if applicable
|
// Drop the Minecraft namespace if applicable
|
||||||
if (instrument.startsWith("minecraft:")) {
|
if (instrument.startsWith("minecraft:")) {
|
||||||
instrument = instrument.substring("minecraft:".length());
|
instrument = instrument.substring("minecraft:".length());
|
||||||
|
@ -39,6 +39,7 @@ import org.cloudburstmc.nbt.NbtMapBuilder;
|
|||||||
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.inventory.item.Enchantment;
|
import org.geysermc.geyser.inventory.item.Enchantment;
|
||||||
|
import org.geysermc.geyser.item.Items;
|
||||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||||
import org.geysermc.geyser.registry.type.ItemMappings;
|
import org.geysermc.geyser.registry.type.ItemMappings;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
@ -93,20 +94,16 @@ public class Item {
|
|||||||
|
|
||||||
/* Translation methods to Bedrock and back */
|
/* Translation methods to Bedrock and back */
|
||||||
|
|
||||||
public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
public ItemData.Builder translateToBedrock(int count, DataComponents components, ItemMapping mapping, ItemMappings mappings) {
|
||||||
if (InventoryUtils.isEmpty(itemStack)) {
|
if (this == Items.AIR || count <= 0) {
|
||||||
// Return, essentially, air
|
// Return, essentially, air
|
||||||
return ItemData.builder();
|
return ItemData.builder();
|
||||||
}
|
}
|
||||||
ItemData.Builder builder = ItemData.builder()
|
ItemData.Builder builder = ItemData.builder()
|
||||||
.definition(mapping.getBedrockDefinition())
|
.definition(mapping.getBedrockDefinition())
|
||||||
.damage(mapping.getBedrockData())
|
.damage(mapping.getBedrockData())
|
||||||
.count(itemStack.getAmount());
|
.count(count);
|
||||||
if (itemStack.getDataComponents() != null) {
|
|
||||||
builder.tag(ItemTranslator.translateNbtToBedrock(itemStack.getDataComponents()));
|
|
||||||
}
|
|
||||||
|
|
||||||
DataComponents components = itemStack.getDataComponents();
|
|
||||||
ItemTranslator.translateCustomItem(components, builder, mapping);
|
ItemTranslator.translateCustomItem(components, builder, mapping);
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
@ -135,6 +132,11 @@ public class Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Integer damage = components.get(DataComponentType.DAMAGE);
|
||||||
|
if (damage != null) {
|
||||||
|
builder.setDamage(damage);
|
||||||
|
}
|
||||||
|
|
||||||
List<Tag> newTags = new ArrayList<>();
|
List<Tag> newTags = new ArrayList<>();
|
||||||
ItemEnchantments enchantments = components.get(DataComponentType.ENCHANTMENTS);
|
ItemEnchantments enchantments = components.get(DataComponentType.ENCHANTMENTS);
|
||||||
if (enchantments != null) {
|
if (enchantments != null) {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@ -41,14 +42,14 @@ public class MapItem extends Item {
|
|||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
Tag mapId = tag.remove("map");
|
Integer mapValue = components.get(DataComponentType.MAP_ID);
|
||||||
if (mapId == null || !(mapId.getValue() instanceof Number number)) return;
|
if (mapValue == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int mapValue = number.intValue();
|
builder.putLong("map_uuid", mapValue);
|
||||||
|
builder.putInt("map_name_index", mapValue);
|
||||||
tag.put(new LongTag("map_uuid", mapValue));
|
builder.putByte("map_display_players", (byte) 1);
|
||||||
tag.put(new IntTag("map_name_index", mapValue));
|
|
||||||
tag.put(new ByteTag("map_display_players", (byte) 1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,16 +25,14 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.text.ChatColor;
|
import org.geysermc.geyser.text.ChatColor;
|
||||||
import org.geysermc.geyser.text.MinecraftLocale;
|
import org.geysermc.geyser.text.MinecraftLocale;
|
||||||
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||||
import org.geysermc.geyser.translator.text.MessageTranslator;
|
|
||||||
|
|
||||||
public class PlayerHeadItem extends Item {
|
public class PlayerHeadItem extends Item {
|
||||||
public PlayerHeadItem(String javaIdentifier, Builder builder) {
|
public PlayerHeadItem(String javaIdentifier, Builder builder) {
|
||||||
@ -45,35 +43,24 @@ public class PlayerHeadItem extends Item {
|
|||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
CompoundTag displayTag;
|
// TODO verify
|
||||||
if (tag.get("display") instanceof CompoundTag existingDisplayTag) {
|
// Also - ChatColor.YELLOW + ChatColor.ITALIC + MessageTranslator.convertMessageLenient(nameTag.getValue(), session.locale())) this code existed if a custom name was already present.
|
||||||
displayTag = existingDisplayTag;
|
// But I think we would always overwrite that because translateDisplayProperties runs after this method.
|
||||||
} else {
|
String customName = builder.getCustomName();
|
||||||
displayTag = new CompoundTag("display");
|
if (customName == null) {
|
||||||
tag.put(displayTag);
|
GameProfile profile = components.get(DataComponentType.PROFILE);
|
||||||
}
|
if (profile != null) {
|
||||||
|
String name = profile.getName();
|
||||||
if (displayTag.get("Name") instanceof StringTag nameTag) {
|
if (name != null) {
|
||||||
// Custom names are always yellow and italic
|
// Add correct name of player skull
|
||||||
displayTag.put(new StringTag("Name", ChatColor.YELLOW + ChatColor.ITALIC + MessageTranslator.convertMessageLenient(nameTag.getValue(), session.locale())));
|
String displayName = ChatColor.RESET + ChatColor.YELLOW +
|
||||||
} else {
|
MinecraftLocale.getLocaleString("block.minecraft.player_head.named", session.locale()).replace("%s", name);
|
||||||
if (tag.contains("SkullOwner")) {
|
builder.setCustomName(displayName);
|
||||||
StringTag name;
|
|
||||||
Tag skullOwner = tag.get("SkullOwner");
|
|
||||||
if (skullOwner instanceof StringTag skullName) {
|
|
||||||
name = skullName;
|
|
||||||
} else {
|
|
||||||
if (skullOwner instanceof CompoundTag && ((CompoundTag) skullOwner).get("Name") instanceof StringTag skullName) {
|
|
||||||
name = skullName;
|
|
||||||
} else {
|
} else {
|
||||||
// No name found so default to "Player Head"
|
// No name found so default to "Player Head"
|
||||||
displayTag.put(new StringTag("Name", ChatColor.RESET + ChatColor.YELLOW + MinecraftLocale.getLocaleString("block.minecraft.player_head", session.locale())));
|
builder.setCustomName(ChatColor.RESET + ChatColor.YELLOW +
|
||||||
return;
|
MinecraftLocale.getLocaleString("block.minecraft.player_head", session.locale()));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Add correct name of player skull
|
|
||||||
String displayName = ChatColor.RESET + ChatColor.YELLOW + MinecraftLocale.getLocaleString("block.minecraft.player_head.named", session.locale()).replace("%s", name.getValue());
|
|
||||||
displayTag.put(new StringTag("Name", displayName));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@ package org.geysermc.geyser.item.type;
|
|||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.PotionContents;
|
import com.github.steveice10.mc.protocol.data.game.item.component.PotionContents;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
|
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
||||||
@ -46,29 +46,27 @@ public class PotionItem extends Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
public ItemData.Builder translateToBedrock(int count, DataComponents components, ItemMapping mapping, ItemMappings mappings) {
|
||||||
if (itemStack.getDataComponents() == null) return super.translateToBedrock(itemStack, mapping, mappings);
|
if (components == null) return super.translateToBedrock(count, components, mapping, mappings);
|
||||||
PotionContents potionContents = itemStack.getDataComponents().get(DataComponentType.POTION_CONTENTS);
|
PotionContents potionContents = components.get(DataComponentType.POTION_CONTENTS);
|
||||||
if (potionContents != null) {
|
if (potionContents != null) {
|
||||||
ItemDefinition customItemDefinition = CustomItemTranslator.getCustomItem(itemStack.getDataComponents(), mapping);
|
ItemDefinition customItemDefinition = CustomItemTranslator.getCustomItem(components, mapping);
|
||||||
if (customItemDefinition == null) {
|
if (customItemDefinition == null) {
|
||||||
Potion potion = Potion.getByJavaIdentifier(((StringTag) potionTag).getValue());
|
Potion potion = Potion.getByJavaIdentifier(((StringTag) potionTag).getValue());
|
||||||
if (potion != null) {
|
if (potion != null) {
|
||||||
return ItemData.builder()
|
return ItemData.builder()
|
||||||
.definition(mapping.getBedrockDefinition())
|
.definition(mapping.getBedrockDefinition())
|
||||||
.damage(potion.getBedrockId())
|
.damage(potion.getBedrockId())
|
||||||
.count(itemStack.getAmount())
|
.count(count);
|
||||||
.tag(ItemTranslator.translateNbtToBedrock(itemStack.getNbt()));
|
|
||||||
}
|
}
|
||||||
GeyserImpl.getInstance().getLogger().debug("Unknown Java potion: " + potionTag.getValue());
|
GeyserImpl.getInstance().getLogger().debug("Unknown Java potion: " + potionTag.getValue());
|
||||||
} else {
|
} else {
|
||||||
return ItemData.builder()
|
return ItemData.builder()
|
||||||
.definition(customItemDefinition)
|
.definition(customItemDefinition)
|
||||||
.count(itemStack.getAmount())
|
.count(count);
|
||||||
.tag(ItemTranslator.translateNbtToBedrock(itemStack.getNbt()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.translateToBedrock(itemStack, mapping, mappings);
|
return super.translateToBedrock(count, components, mapping, mappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,7 +83,7 @@ public class ShulkerBoxItem extends BlockItem {
|
|||||||
|
|
||||||
itemsList.add(boxItemNbt.build());
|
itemsList.add(boxItemNbt.build());
|
||||||
}
|
}
|
||||||
builder.getOrCreateNbt().putList("Items", NbtType.COMPOUND, itemsList);
|
builder.putList("Items", NbtType.COMPOUND, itemsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.ItemStack;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
||||||
@ -41,7 +41,7 @@ public class TippedArrowItem extends ArrowItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
public ItemData.Builder translateToBedrock(int count, DataComponents components, ItemMapping mapping, ItemMappings mappings) {
|
||||||
Tag potionTag = itemStack.getNbt().get("Potion");
|
Tag potionTag = itemStack.getNbt().get("Potion");
|
||||||
if (potionTag instanceof StringTag) {
|
if (potionTag instanceof StringTag) {
|
||||||
TippedArrowPotion tippedArrowPotion = TippedArrowPotion.getByJavaIdentifier(((StringTag) potionTag).getValue());
|
TippedArrowPotion tippedArrowPotion = TippedArrowPotion.getByJavaIdentifier(((StringTag) potionTag).getValue());
|
||||||
@ -49,11 +49,10 @@ public class TippedArrowItem extends ArrowItem {
|
|||||||
return ItemData.builder()
|
return ItemData.builder()
|
||||||
.definition(mapping.getBedrockDefinition())
|
.definition(mapping.getBedrockDefinition())
|
||||||
.damage(tippedArrowPotion.getBedrockId())
|
.damage(tippedArrowPotion.getBedrockId())
|
||||||
.count(itemStack.getAmount())
|
.count(count);
|
||||||
.tag(ItemTranslator.translateNbtToBedrock(itemStack.getNbt()));
|
|
||||||
}
|
}
|
||||||
GeyserImpl.getInstance().getLogger().debug("Unknown Java potion (tipped arrow): " + potionTag.getValue());
|
GeyserImpl.getInstance().getLogger().debug("Unknown Java potion (tipped arrow): " + potionTag.getValue());
|
||||||
}
|
}
|
||||||
return super.translateToBedrock(itemStack, mapping, mappings);
|
return super.translateToBedrock(count, components, mapping, mappings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -53,10 +54,10 @@ public class TropicalFishBucketItem extends Item {
|
|||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
// Prevent name from appearing as "Bucket of"
|
// Prevent name from appearing as "Bucket of"
|
||||||
tag.put(new ByteTag("AppendCustomName", (byte) 1));
|
builder.putByte("AppendCustomName", (byte) 1);
|
||||||
tag.put(new StringTag("CustomName", MinecraftLocale.getLocaleString("entity.minecraft.tropical_fish", session.locale())));
|
builder.putString("CustomName", MinecraftLocale.getLocaleString("entity.minecraft.tropical_fish", session.locale()));
|
||||||
// Add Java's client side lore tag
|
// Add Java's client side lore tag
|
||||||
Tag bucketVariantTag = tag.get("BucketVariantTag");
|
components.get(DataComponentType)
|
||||||
if (bucketVariantTag instanceof IntTag) {
|
if (bucketVariantTag instanceof IntTag) {
|
||||||
CompoundTag displayTag = tag.get("display");
|
CompoundTag displayTag = tag.get("display");
|
||||||
if (displayTag == null) {
|
if (displayTag == null) {
|
||||||
|
@ -25,12 +25,18 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.Filterable;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.WritableBookContent;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.cloudburstmc.nbt.NbtMap;
|
||||||
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
|
import org.cloudburstmc.nbt.NbtType;
|
||||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||||
@ -48,22 +54,20 @@ public class WritableBookItem extends Item {
|
|||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
ListTag pagesTag = tag.remove("pages");
|
WritableBookContent bookContent = components.get(DataComponentType.WRITABLE_BOOK_CONTENT);
|
||||||
if (pagesTag == null) {
|
if (bookContent == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<Tag> pages = new ArrayList<>();
|
|
||||||
for (Tag subTag : pagesTag.getValue()) {
|
|
||||||
if (!(subTag instanceof StringTag textTag))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
CompoundTag pageTag = new CompoundTag("");
|
List<NbtMap> bedrockPages = new ArrayList<>();
|
||||||
pageTag.put(new StringTag("photoname", ""));
|
for (Filterable<String> page : bookContent.getPages()) {
|
||||||
pageTag.put(new StringTag("text", MessageTranslator.convertMessageLenient(textTag.getValue())));
|
NbtMapBuilder pageBuilder = NbtMap.builder();
|
||||||
pages.add(pageTag);
|
pageBuilder.putString("photoname", "");
|
||||||
|
pageBuilder.putString("text", MessageTranslator.convertMessageLenient(page.getRaw()));
|
||||||
|
bedrockPages.add(pageBuilder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.put(new ListTag("pages", pages));
|
builder.putList("pages", NbtType.COMPOUND, bedrockPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,21 +25,27 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.Filterable;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.item.component.WrittenBookContent;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.cloudburstmc.nbt.NbtMap;
|
||||||
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
|
import org.cloudburstmc.nbt.NbtType;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||||
import org.geysermc.geyser.translator.text.MessageTranslator;
|
import org.geysermc.geyser.translator.text.MessageTranslator;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class WrittenBookItem extends WritableBookItem {
|
public class WrittenBookItem extends Item {
|
||||||
public static final int MAXIMUM_PAGE_EDIT_LENGTH = 1024;
|
public static final int MAXIMUM_PAGE_EDIT_LENGTH = 1024;
|
||||||
public static final int MAXIMUM_PAGE_LENGTH = 32768;
|
public static final int MAXIMUM_PAGE_LENGTH = 32768;
|
||||||
public static final int MAXIMUM_PAGE_COUNT = 100; // Java edition limit. Bedrock edition has a limit of 50 pages.
|
public static final int MAXIMUM_PAGE_COUNT = 100; // Java edition limit. Bedrock edition has a limit of 50 pages.
|
||||||
@ -51,25 +57,24 @@ public class WrittenBookItem extends WritableBookItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
||||||
boolean isValid = isValidWrittenBook(tag);
|
|
||||||
if (!isValid) {
|
|
||||||
tag.remove("pages");
|
|
||||||
}
|
|
||||||
|
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
if (!isValid) {
|
WrittenBookContent bookContent = components.get(DataComponentType.WRITTEN_BOOK_CONTENT);
|
||||||
CompoundTag invalidTagPage = new CompoundTag("");
|
if (bookContent == null) {
|
||||||
invalidTagPage.put(new StringTag("photoname", ""));
|
return;
|
||||||
invalidTagPage.put(new StringTag(
|
|
||||||
"text",
|
|
||||||
MessageTranslator.convertMessage(
|
|
||||||
Component.translatable("book.invalid.tag", NamedTextColor.DARK_RED),
|
|
||||||
session.locale()
|
|
||||||
)
|
|
||||||
));
|
|
||||||
tag.put(new ListTag("pages", List.of(invalidTagPage)));
|
|
||||||
}
|
}
|
||||||
|
List<NbtMap> bedrockPages = new ArrayList<>();
|
||||||
|
for (Filterable<Component> page : bookContent.getPages()) {
|
||||||
|
NbtMapBuilder pageBuilder = NbtMap.builder();
|
||||||
|
pageBuilder.putString("photoname", "");
|
||||||
|
pageBuilder.putString("text", MessageTranslator.convertMessage(page.getRaw()));
|
||||||
|
bedrockPages.add(pageBuilder.build());
|
||||||
|
}
|
||||||
|
builder.putList("pages", NbtType.COMPOUND, bedrockPages);
|
||||||
|
|
||||||
|
builder.putString("title", bookContent.getTitle().getRaw())
|
||||||
|
.putString("author", bookContent.getAuthor());
|
||||||
|
// TODO isResolved
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isValidWrittenBook(CompoundTag tag) {
|
private boolean isValidWrittenBook(CompoundTag tag) {
|
||||||
|
@ -34,6 +34,7 @@ import org.geysermc.geyser.registry.type.ItemMapping;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.OptionalInt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An intermediary class made to allow easy access to work-in-progress NBT, such as lore and display.
|
* An intermediary class made to allow easy access to work-in-progress NBT, such as lore and display.
|
||||||
@ -44,12 +45,18 @@ public final class BedrockItemBuilder {
|
|||||||
private String customName;
|
private String customName;
|
||||||
@Nullable
|
@Nullable
|
||||||
private List<String> lore;
|
private List<String> lore;
|
||||||
|
private OptionalInt damage = OptionalInt.empty();
|
||||||
/**
|
/**
|
||||||
* Miscellaneous NBT that will be put into the final item.
|
* Miscellaneous NBT that will be put into the final item.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private NbtMapBuilder builder;
|
private NbtMapBuilder builder;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getCustomName() {
|
||||||
|
return customName;
|
||||||
|
}
|
||||||
|
|
||||||
public BedrockItemBuilder setCustomName(String customName) {
|
public BedrockItemBuilder setCustomName(String customName) {
|
||||||
this.customName = customName;
|
this.customName = customName;
|
||||||
return this;
|
return this;
|
||||||
@ -63,6 +70,15 @@ public final class BedrockItemBuilder {
|
|||||||
return lore;
|
return lore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OptionalInt getDamage() {
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BedrockItemBuilder setDamage(int damage) {
|
||||||
|
this.damage = OptionalInt.of(damage);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public NbtMapBuilder getOrCreateNbt() {
|
public NbtMapBuilder getOrCreateNbt() {
|
||||||
if (builder == null) {
|
if (builder == null) {
|
||||||
@ -85,6 +101,14 @@ public final class BedrockItemBuilder {
|
|||||||
return getOrCreateNbt().putInt(name, value);
|
return getOrCreateNbt().putInt(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> NbtMapBuilder putList(String name, NbtType<T> type, List<T> value) {
|
||||||
|
return getOrCreateNbt().putList(name, type, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NbtMapBuilder putLong(String name, long value) {
|
||||||
|
return getOrCreateNbt().putLong(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
public NbtMapBuilder putString(String name, String value) {
|
public NbtMapBuilder putString(String name, String value) {
|
||||||
return getOrCreateNbt().putString(name, value);
|
return getOrCreateNbt().putString(name, value);
|
||||||
}
|
}
|
||||||
@ -108,6 +132,9 @@ public final class BedrockItemBuilder {
|
|||||||
}
|
}
|
||||||
getOrCreateNbt().put("display", display.build());
|
getOrCreateNbt().put("display", display.build());
|
||||||
}
|
}
|
||||||
|
if (damage.isPresent()) {
|
||||||
|
getOrCreateNbt().putInt("Damage", damage.getAsInt());
|
||||||
|
}
|
||||||
if (builder == null) {
|
if (builder == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -161,9 +161,9 @@ public final class ItemTranslator {
|
|||||||
addAdvancedTooltips(components, nbtBuilder, javaItem, session.locale());
|
addAdvancedTooltips(components, nbtBuilder, javaItem, session.locale());
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack itemStack = new ItemStack(javaItem.javaId(), count, components);
|
ItemData.Builder builder = javaItem.translateToBedrock(count, components, bedrockItem, session.getItemMappings());
|
||||||
|
// Finalize the Bedrock NBT
|
||||||
ItemData.Builder builder = javaItem.translateToBedrock(itemStack, bedrockItem, session.getItemMappings());
|
builder.tag(nbtBuilder.build());
|
||||||
if (bedrockItem.isBlock()) {
|
if (bedrockItem.isBlock()) {
|
||||||
CustomBlockData customBlockData = BlockRegistries.CUSTOM_BLOCK_ITEM_OVERRIDES.getOrDefault(
|
CustomBlockData customBlockData = BlockRegistries.CUSTOM_BLOCK_ITEM_OVERRIDES.getOrDefault(
|
||||||
bedrockItem.getJavaItem().javaIdentifier(), null);
|
bedrockItem.getJavaItem().javaIdentifier(), null);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren