mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Here's the idea so far
This commit is contained in:
parent
099e968bde
commit
c1edf20734
27 changed files with 241 additions and 204 deletions
|
@ -26,7 +26,7 @@
|
||||||
package org.geysermc.geyser.inventory;
|
package org.geysermc.geyser.inventory;
|
||||||
|
|
||||||
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.DataComponentPatch;
|
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.CompoundTag;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -35,7 +35,6 @@ import lombok.Getter;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
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.item.Items;
|
import org.geysermc.geyser.item.Items;
|
||||||
import org.geysermc.geyser.item.type.Item;
|
import org.geysermc.geyser.item.type.Item;
|
||||||
import org.geysermc.geyser.registry.Registries;
|
import org.geysermc.geyser.registry.Registries;
|
||||||
|
@ -49,18 +48,18 @@ public class GeyserItemStack {
|
||||||
|
|
||||||
private final int javaId;
|
private final int javaId;
|
||||||
private int amount;
|
private int amount;
|
||||||
private DataComponentPatch components;
|
private DataComponents components;
|
||||||
private int netId;
|
private int netId;
|
||||||
|
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
@EqualsAndHashCode.Exclude
|
@EqualsAndHashCode.Exclude
|
||||||
private Item item;
|
private Item item;
|
||||||
|
|
||||||
private GeyserItemStack(int javaId, int amount, DataComponentPatch components) {
|
private GeyserItemStack(int javaId, int amount, DataComponents components) {
|
||||||
this(javaId, amount, components, 1);
|
this(javaId, amount, components, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GeyserItemStack(int javaId, int amount, DataComponentPatch components, int netId) {
|
private GeyserItemStack(int javaId, int amount, DataComponents components, int netId) {
|
||||||
this.javaId = javaId;
|
this.javaId = javaId;
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.components = components;
|
this.components = components;
|
||||||
|
@ -68,7 +67,7 @@ public class GeyserItemStack {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NonNull GeyserItemStack from(@Nullable ItemStack itemStack) {
|
public static @NonNull GeyserItemStack from(@Nullable ItemStack itemStack) {
|
||||||
return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getDataComponentPatch());
|
return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getDataComponents());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getJavaId() {
|
public int getJavaId() {
|
||||||
|
@ -84,7 +83,7 @@ public class GeyserItemStack {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable DataComponentPatch getComponents() {
|
public @Nullable DataComponents getComponents() {
|
||||||
return isEmpty() ? null : components;
|
return isEmpty() ? null : components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.CompoundTag;
|
||||||
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;
|
||||||
|
@ -43,7 +43,7 @@ public class ArmorItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
if (tag.get("Trim") instanceof CompoundTag trim) {
|
if (tag.get("Trim") instanceof CompoundTag trim) {
|
||||||
|
|
|
@ -46,9 +46,9 @@ public class ArrowItem extends Item {
|
||||||
TippedArrowPotion tippedArrowPotion = TippedArrowPotion.getByBedrockId(itemData.getDamage());
|
TippedArrowPotion tippedArrowPotion = TippedArrowPotion.getByBedrockId(itemData.getDamage());
|
||||||
ItemStack itemStack = super.translateToJava(itemData, mapping, mappings);
|
ItemStack itemStack = super.translateToJava(itemData, mapping, mappings);
|
||||||
if (tippedArrowPotion != null) {
|
if (tippedArrowPotion != null) {
|
||||||
itemStack = Items.TIPPED_ARROW.newItemStack(itemStack.getAmount(), itemStack.getDataComponentPatch());
|
itemStack = Items.TIPPED_ARROW.newItemStack(itemStack.getAmount(), itemStack.getDataComponents());
|
||||||
StringTag potionTag = new StringTag("Potion", tippedArrowPotion.getJavaIdentifier());
|
StringTag potionTag = new StringTag("Potion", tippedArrowPotion.getJavaIdentifier());
|
||||||
itemStack.getDataComponentPatch().put(DataComponentType.POTION_CONTENTS, new PotionContents());
|
itemStack.getDataComponents().put(DataComponentType.POTION_CONTENTS, new PotionContents());
|
||||||
}
|
}
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||||
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;
|
||||||
|
@ -39,7 +39,7 @@ public class AxolotlBucketItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
// Bedrock Edition displays the properties of the axolotl. Java does not.
|
// Bedrock Edition displays the properties of the axolotl. Java does not.
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
|
@ -122,7 +122,7 @@ public class BannerItem extends BlockItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
CompoundTag blockEntityTag = tag.remove("BlockEntityTag");
|
CompoundTag blockEntityTag = tag.remove("BlockEntityTag");
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
|
@ -37,7 +37,7 @@ public class ChestItem extends BlockItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
// Strip the BlockEntityTag from the chests contents
|
// Strip the BlockEntityTag from the chests contents
|
||||||
|
|
|
@ -26,7 +26,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.ItemStack;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentPatch;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||||
|
@ -60,7 +60,7 @@ public class CompassItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
Tag lodestoneTag = tag.get("LodestoneTracked");
|
Tag lodestoneTag = tag.get("LodestoneTracked");
|
||||||
|
|
|
@ -26,7 +26,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.ItemStack;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentPatch;
|
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;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
@ -42,7 +42,7 @@ public class CrossbowItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
ListTag chargedProjectiles = tag.get("ChargedProjectiles");
|
ListTag chargedProjectiles = tag.get("ChargedProjectiles");
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
@ -39,7 +39,7 @@ public class DecoratedPotItem extends BlockItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
if (tag.remove("BlockEntityTag") instanceof CompoundTag blockEntityTag) {
|
if (tag.remove("BlockEntityTag") instanceof CompoundTag blockEntityTag) {
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.CompoundTag;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
|
@ -40,7 +40,7 @@ public class DyeableArmorItem extends ArmorItem implements DyeableLeatherItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
DyeableLeatherItem.translateNbtToBedrock(tag);
|
DyeableLeatherItem.translateNbtToBedrock(tag);
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.CompoundTag;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
|
@ -39,7 +39,7 @@ public class DyeableHorseArmorItem extends Item implements DyeableLeatherItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
DyeableLeatherItem.translateNbtToBedrock(tag);
|
DyeableLeatherItem.translateNbtToBedrock(tag);
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
|
@ -42,7 +42,7 @@ public class EnchantedBookItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
List<Tag> newTags = new ArrayList<>();
|
List<Tag> newTags = new ArrayList<>();
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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;
|
||||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
|
@ -40,7 +40,7 @@ public class FireworkRocketItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
CompoundTag fireworks = tag.get("Fireworks");
|
CompoundTag fireworks = tag.get("Fireworks");
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||||
|
@ -41,7 +41,7 @@ public class FireworkStarItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
Tag explosion = tag.remove("Explosion");
|
Tag explosion = tag.remove("Explosion");
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.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;
|
||||||
|
@ -38,7 +38,7 @@ public class FishingRodItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
// Fix damage inconsistency
|
// Fix damage inconsistency
|
||||||
|
|
|
@ -27,7 +27,7 @@ package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||||
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.DataComponentPatch;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
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.ItemEnchantments;
|
import com.github.steveice10.mc.protocol.data.game.item.component.ItemEnchantments;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.*;
|
import com.github.steveice10.opennbt.tag.builtin.*;
|
||||||
|
@ -103,12 +103,12 @@ public class Item {
|
||||||
.definition(mapping.getBedrockDefinition())
|
.definition(mapping.getBedrockDefinition())
|
||||||
.damage(mapping.getBedrockData())
|
.damage(mapping.getBedrockData())
|
||||||
.count(itemStack.getAmount());
|
.count(itemStack.getAmount());
|
||||||
if (itemStack.getNbt() != null) {
|
if (itemStack.getDataComponents() != null) {
|
||||||
builder.tag(ItemTranslator.translateNbtToBedrock(itemStack.getNbt()));
|
builder.tag(ItemTranslator.translateNbtToBedrock(itemStack.getDataComponents()));
|
||||||
}
|
}
|
||||||
|
|
||||||
CompoundTag nbt = itemStack.getNbt();
|
DataComponents components = itemStack.getDataComponents();
|
||||||
ItemTranslator.translateCustomItem(nbt, builder, mapping);
|
ItemTranslator.translateCustomItem(components, builder, mapping);
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ public class Item {
|
||||||
/**
|
/**
|
||||||
* Takes components from Java Edition and map them into Bedrock.
|
* Takes components from Java Edition and map them into Bedrock.
|
||||||
*/
|
*/
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
// // Basing off of ItemStack#getHoverName as of 1.20.5. VERIFY??
|
// // Basing off of ItemStack#getHoverName as of 1.20.5. VERIFY??
|
||||||
// Component customName = components.get(DataComponentType.CUSTOM_NAME);
|
// Component customName = components.get(DataComponentType.CUSTOM_NAME);
|
||||||
// if (customName == null) {
|
// if (customName == null) {
|
||||||
|
@ -271,7 +271,7 @@ public class Item {
|
||||||
|
|
||||||
/* Translation methods end */
|
/* Translation methods end */
|
||||||
|
|
||||||
public ItemStack newItemStack(int count, DataComponentPatch components) {
|
public ItemStack newItemStack(int count, DataComponents components) {
|
||||||
return new ItemStack(this.javaId, count, components);
|
return new ItemStack(this.javaId, count, components);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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;
|
||||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
|
@ -38,7 +38,7 @@ public class MapItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
Tag mapId = tag.remove("map");
|
Tag mapId = tag.remove("map");
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.CompoundTag;
|
||||||
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;
|
||||||
|
@ -42,7 +42,7 @@ public class PlayerHeadItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
CompoundTag displayTag;
|
CompoundTag displayTag;
|
||||||
|
|
|
@ -47,10 +47,10 @@ public class PotionItem extends Item {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
public ItemData.Builder translateToBedrock(ItemStack itemStack, ItemMapping mapping, ItemMappings mappings) {
|
||||||
if (itemStack.getDataComponentPatch() == null) return super.translateToBedrock(itemStack, mapping, mappings);
|
if (itemStack.getDataComponents() == null) return super.translateToBedrock(itemStack, mapping, mappings);
|
||||||
PotionContents potionContents = itemStack.getDataComponentPatch().get(DataComponentType.POTION_CONTENTS);
|
PotionContents potionContents = itemStack.getDataComponents().get(DataComponentType.POTION_CONTENTS);
|
||||||
if (potionContents != null) {
|
if (potionContents != null) {
|
||||||
ItemDefinition customItemDefinition = CustomItemTranslator.getCustomItem(itemStack.getDataComponentPatch(), mapping);
|
ItemDefinition customItemDefinition = CustomItemTranslator.getCustomItem(itemStack.getDataComponents(), 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) {
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
|
@ -41,7 +41,7 @@ public class ShieldItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
if (tag.remove("BlockEntityTag") instanceof CompoundTag blockEntityTag) {
|
if (tag.remove("BlockEntityTag") instanceof CompoundTag blockEntityTag) {
|
||||||
|
|
|
@ -25,11 +25,10 @@
|
||||||
|
|
||||||
package org.geysermc.geyser.item.type;
|
package org.geysermc.geyser.item.type;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
|
||||||
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.DataComponentPatch;
|
|
||||||
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.opennbt.tag.builtin.*;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
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;
|
||||||
|
@ -38,7 +37,6 @@ import org.geysermc.geyser.item.Items;
|
||||||
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.ItemTranslator;
|
import org.geysermc.geyser.translator.item.ItemTranslator;
|
||||||
import org.geysermc.geyser.util.MathUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -49,7 +47,7 @@ public class ShulkerBoxItem extends BlockItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
List<ItemStack> contents = components.get(DataComponentType.CONTAINER);
|
List<ItemStack> contents = components.get(DataComponentType.CONTAINER);
|
||||||
|
@ -73,9 +71,16 @@ public class ShulkerBoxItem extends BlockItem {
|
||||||
boxItemNbt.putShort("Damage", (short) boxMapping.getBedrockData());
|
boxItemNbt.putShort("Damage", (short) boxMapping.getBedrockData());
|
||||||
boxItemNbt.putByte("Count", (byte) item.getAmount());
|
boxItemNbt.putByte("Count", (byte) item.getAmount());
|
||||||
// Only the display name is what we have interest in, so just translate that if relevant
|
// Only the display name is what we have interest in, so just translate that if relevant
|
||||||
DataComponentPatch boxComponents = item.getDataComponentPatch();
|
DataComponents boxComponents = item.getDataComponents();
|
||||||
if (boxComponents != null) {
|
if (boxComponents != null) {
|
||||||
boxItemNbt.put(ItemTranslator.translateDisplayProperties(session, displayTag, boxMapping, '7'));
|
String customName = ItemTranslator.getCustomName(session, boxComponents, boxMapping, '7');
|
||||||
|
if (customName != null) {
|
||||||
|
boxItemNbt.putCompound("tag", NbtMap.builder()
|
||||||
|
.putCompound("display", NbtMap.builder()
|
||||||
|
.putString("Name", customName)
|
||||||
|
.build())
|
||||||
|
.build());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
itemsList.add(boxItemNbt.build());
|
itemsList.add(boxItemNbt.build());
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
@ -49,7 +49,7 @@ public class TropicalFishBucketItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
// Prevent name from appearing as "Bucket of"
|
// Prevent name from appearing as "Bucket of"
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.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;
|
||||||
|
@ -45,7 +45,7 @@ public class WritableBookItem extends Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
ListTag pagesTag = tag.remove("pages");
|
ListTag pagesTag = tag.remove("pages");
|
||||||
|
|
|
@ -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.component.DataComponentPatch;
|
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.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;
|
||||||
|
@ -50,7 +50,7 @@ public class WrittenBookItem extends WritableBookItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponentPatch components, @NonNull NbtMapBuilder builder) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull NbtMapBuilder builder) {
|
||||||
boolean isValid = isValidWrittenBook(tag);
|
boolean isValid = isValidWrittenBook(tag);
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
tag.remove("pages");
|
tag.remove("pages");
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* @author GeyserMC
|
||||||
|
* @link https://github.com/GeyserMC/Geyser
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.geysermc.geyser.translator.item;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.cloudburstmc.nbt.NbtMap;
|
||||||
|
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||||
|
import org.cloudburstmc.nbt.NbtType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An intermediary class made to allow easy access to work-in-progress NBT, such as lore and display.
|
||||||
|
*/
|
||||||
|
public final class BedrockItemBuilder {
|
||||||
|
// All Bedrock-style
|
||||||
|
@Nullable
|
||||||
|
private String customName;
|
||||||
|
@Nullable
|
||||||
|
private List<String> lore;
|
||||||
|
/**
|
||||||
|
* Miscellaneous NBT that will be put into the final item.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
private NbtMapBuilder builder;
|
||||||
|
|
||||||
|
public BedrockItemBuilder setCustomName(String customName) {
|
||||||
|
this.customName = customName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public List<String> getOrCreateLore() {
|
||||||
|
if (lore == null) {
|
||||||
|
lore = new ArrayList<>();
|
||||||
|
}
|
||||||
|
return lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public NbtMapBuilder getOrCreateNbt() {
|
||||||
|
if (builder == null) {
|
||||||
|
builder = NbtMap.builder();
|
||||||
|
}
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return null if no NBT is needed on this item.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public NbtMap build() {
|
||||||
|
if (customName != null || lore != null) {
|
||||||
|
NbtMapBuilder display = NbtMap.builder();
|
||||||
|
if (customName != null) {
|
||||||
|
display.putString("Name", customName);
|
||||||
|
}
|
||||||
|
if (lore != null) {
|
||||||
|
display.putList("Lore", NbtType.STRING, lore);
|
||||||
|
}
|
||||||
|
getOrCreateNbt().put("display", display.build());
|
||||||
|
}
|
||||||
|
if (builder == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
package org.geysermc.geyser.translator.item;
|
package org.geysermc.geyser.translator.item;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentPatch;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentType;
|
||||||
import it.unimi.dsi.fastutil.Pair;
|
import it.unimi.dsi.fastutil.Pair;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
@ -43,7 +43,7 @@ import java.util.OptionalInt;
|
||||||
public final class CustomItemTranslator {
|
public final class CustomItemTranslator {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static ItemDefinition getCustomItem(DataComponentPatch components, ItemMapping mapping) {
|
public static ItemDefinition getCustomItem(DataComponents components, ItemMapping mapping) {
|
||||||
if (components == null) {
|
if (components == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -52,10 +52,9 @@ public final class CustomItemTranslator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO getOrDefault
|
int customModelData = components.getOrDefault(DataComponentType.CUSTOM_MODEL_DATA, 0);
|
||||||
int customModelData = components.get(DataComponentType.CUSTOM_MODEL_DATA);
|
|
||||||
boolean checkDamage = mapping.getJavaItem().maxDamage() > 0;
|
boolean checkDamage = mapping.getJavaItem().maxDamage() > 0;
|
||||||
int damage = !checkDamage ? 0 : components.get(DataComponentType.DAMAGE);
|
int damage = !checkDamage ? 0 : components.getOrDefault(DataComponentType.DAMAGE, 0);
|
||||||
boolean unbreakable = checkDamage && !isDamaged(components, damage);
|
boolean unbreakable = checkDamage && !isDamaged(components, damage);
|
||||||
|
|
||||||
for (Pair<CustomItemOptions, ItemDefinition> mappingTypes : customMappings) {
|
for (Pair<CustomItemOptions, ItemDefinition> mappingTypes : customMappings) {
|
||||||
|
@ -105,11 +104,11 @@ public final class CustomItemTranslator {
|
||||||
|
|
||||||
/* These two functions are based off their Mojmap equivalents from 1.19.2 */
|
/* These two functions are based off their Mojmap equivalents from 1.19.2 */
|
||||||
|
|
||||||
private static boolean isDamaged(DataComponentPatch components, int damage) {
|
private static boolean isDamaged(DataComponents components, int damage) {
|
||||||
return isDamagableItem(components) && damage > 0;
|
return isDamagableItem(components) && damage > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isDamagableItem(DataComponentPatch components) {
|
private static boolean isDamagableItem(DataComponents components) {
|
||||||
// mapping.getMaxDamage > 0 should also be checked (return false if not true) but we already check prior to this function
|
// mapping.getMaxDamage > 0 should also be checked (return false if not true) but we already check prior to this function
|
||||||
Boolean unbreakable = components.get(DataComponentType.UNBREAKABLE);
|
Boolean unbreakable = components.get(DataComponentType.UNBREAKABLE);
|
||||||
// Tag must either not be present or be set to false
|
// Tag must either not be present or be set to false
|
||||||
|
|
|
@ -25,11 +25,12 @@
|
||||||
|
|
||||||
package org.geysermc.geyser.translator.item;
|
package org.geysermc.geyser.translator.item;
|
||||||
|
|
||||||
|
import com.github.steveice10.mc.auth.data.GameProfile;
|
||||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.attribute.ModifierOperation;
|
import com.github.steveice10.mc.protocol.data.game.entity.attribute.ModifierOperation;
|
||||||
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.AdventureModePredicate;
|
import com.github.steveice10.mc.protocol.data.game.item.component.AdventureModePredicate;
|
||||||
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponentPatch;
|
import com.github.steveice10.mc.protocol.data.game.item.component.DataComponents;
|
||||||
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.ItemAttributeModifiers;
|
import com.github.steveice10.mc.protocol.data.game.item.component.ItemAttributeModifiers;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
||||||
|
@ -83,7 +84,6 @@ public final class ItemTranslator {
|
||||||
*/
|
*/
|
||||||
private static final String[] ALL_SLOTS = new String[]{"mainhand", "offhand", "feet", "legs", "chest", "head"};
|
private static final String[] ALL_SLOTS = new String[]{"mainhand", "offhand", "feet", "legs", "chest", "head"};
|
||||||
private static final DecimalFormat ATTRIBUTE_FORMAT = new DecimalFormat("0.#####");
|
private static final DecimalFormat ATTRIBUTE_FORMAT = new DecimalFormat("0.#####");
|
||||||
private static final byte HIDE_ATTRIBUTES_FLAG = 1 << 1;
|
|
||||||
|
|
||||||
private ItemTranslator() {
|
private ItemTranslator() {
|
||||||
}
|
}
|
||||||
|
@ -102,23 +102,23 @@ public final class ItemTranslator {
|
||||||
|
|
||||||
ItemStack itemStack = javaItem.translateToJava(data, bedrockItem, mappings);
|
ItemStack itemStack = javaItem.translateToJava(data, bedrockItem, mappings);
|
||||||
|
|
||||||
if (itemStack.getNbt() != null) {
|
// if (itemStack.getNbt() != null) {
|
||||||
javaItem.translateNbtToJava(itemStack.getNbt(), bedrockItem);
|
// javaItem.translateNbtToJava(itemStack.getNbt(), bedrockItem);
|
||||||
if (itemStack.getNbt().isEmpty()) {
|
// if (itemStack.getNbt().isEmpty()) {
|
||||||
// Otherwise, seems to cause issues with villagers accepting books, and I don't see how this will break anything else. - Camotoy
|
// // Otherwise, seems to cause issues with villagers accepting books, and I don't see how this will break anything else. - Camotoy
|
||||||
itemStack = new ItemStack(itemStack.getId(), itemStack.getAmount(), null);
|
// itemStack = new ItemStack(itemStack.getId(), itemStack.getAmount(), null);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, int javaId, int count, CompoundTag tag) {
|
public static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, int javaId, int count, DataComponents components) {
|
||||||
ItemMapping bedrockItem = session.getItemMappings().getMapping(javaId);
|
ItemMapping bedrockItem = session.getItemMappings().getMapping(javaId);
|
||||||
if (bedrockItem == ItemMapping.AIR) {
|
if (bedrockItem == ItemMapping.AIR) {
|
||||||
session.getGeyser().getLogger().debug("ItemMapping returned air: " + javaId);
|
session.getGeyser().getLogger().debug("ItemMapping returned air: " + javaId);
|
||||||
return ItemData.builder();
|
return ItemData.builder();
|
||||||
}
|
}
|
||||||
return translateToBedrock(session, Registries.JAVA_ITEMS.get().get(javaId), bedrockItem, count, tag);
|
return translateToBedrock(session, Registries.JAVA_ITEMS.get().get(javaId), bedrockItem, count, components);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -133,32 +133,35 @@ public final class ItemTranslator {
|
||||||
return ItemData.AIR;
|
return ItemData.AIR;
|
||||||
}
|
}
|
||||||
// Java item needs to be loaded separately. The mapping for tipped arrow would
|
// Java item needs to be loaded separately. The mapping for tipped arrow would
|
||||||
return translateToBedrock(session, Registries.JAVA_ITEMS.get().get(stack.getId()), bedrockItem, stack.getAmount(), stack.getNbt())
|
return translateToBedrock(session, Registries.JAVA_ITEMS.get().get(stack.getId()), bedrockItem, stack.getAmount(), stack.getDataComponents())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, Item javaItem, ItemMapping bedrockItem, int count, DataComponentPatch components) {
|
private static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, Item javaItem, ItemMapping bedrockItem, int count, DataComponents components) {
|
||||||
NbtMapBuilder builder = NbtMap.builder();
|
BedrockItemBuilder nbtBuilder = new BedrockItemBuilder();
|
||||||
|
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
javaItem.translateComponentsToBedrock(session, components, builder);
|
javaItem.translateComponentsToBedrock(session, components, nbtBuilder.getOrCreateNbt());
|
||||||
}
|
}
|
||||||
|
|
||||||
translateDisplayProperties(session, components, bedrockItem);
|
String customName = getCustomName(session, components, bedrockItem);
|
||||||
|
if (customName != null) {
|
||||||
|
nbtBuilder.setCustomName(customName);
|
||||||
|
}
|
||||||
|
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
ItemAttributeModifiers attributeModifiers = components.get(DataComponentType.ATTRIBUTE_MODIFIERS);
|
ItemAttributeModifiers attributeModifiers = components.get(DataComponentType.ATTRIBUTE_MODIFIERS);
|
||||||
if (attributeModifiers != null && attributeModifiers.isShowInTooltip()) {
|
if (attributeModifiers != null && attributeModifiers.isShowInTooltip()) {
|
||||||
// only add if attribute modifiers do not indicate to hide them
|
// only add if attribute modifiers do not indicate to hide them
|
||||||
addAttributeLore(attributeModifiers, builder, session.locale());
|
addAttributeLore(attributeModifiers, nbtBuilder, session.locale());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.isAdvancedTooltips()) {
|
if (session.isAdvancedTooltips()) {
|
||||||
nbt = addAdvancedTooltips(nbt, javaItem, session.locale());
|
addAdvancedTooltips(components, nbtBuilder, javaItem, session.locale());
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack itemStack = new ItemStack(javaItem.javaId(), count, nbt);
|
ItemStack itemStack = new ItemStack(javaItem.javaId(), count, components);
|
||||||
|
|
||||||
ItemData.Builder builder = javaItem.translateToBedrock(itemStack, bedrockItem, session.getItemMappings());
|
ItemData.Builder builder = javaItem.translateToBedrock(itemStack, bedrockItem, session.getItemMappings());
|
||||||
if (bedrockItem.isBlock()) {
|
if (bedrockItem.isBlock()) {
|
||||||
|
@ -172,10 +175,10 @@ public final class ItemTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bedrockItem.getJavaItem().equals(Items.PLAYER_HEAD)) {
|
if (bedrockItem.getJavaItem().equals(Items.PLAYER_HEAD)) {
|
||||||
translatePlayerHead(session, nbt, builder);
|
translatePlayerHead(session, components, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
translateCustomItem(nbt, builder, bedrockItem);
|
translateCustomItem(components, builder, bedrockItem);
|
||||||
|
|
||||||
if (components != null) {
|
if (components != null) {
|
||||||
// Translate the canDestroy and canPlaceOn Java NBT
|
// Translate the canDestroy and canPlaceOn Java NBT
|
||||||
|
@ -198,21 +201,12 @@ public final class ItemTranslator {
|
||||||
* Bedrock Edition does not see attribute modifiers like Java Edition does,
|
* Bedrock Edition does not see attribute modifiers like Java Edition does,
|
||||||
* so we add them as lore instead.
|
* so we add them as lore instead.
|
||||||
*
|
*
|
||||||
* @param nbt the NBT of the ItemStack
|
* @param modifiers the attribute modifiers of the ItemStack
|
||||||
* @param language the locale of the player
|
* @param language the locale of the player
|
||||||
*/
|
*/
|
||||||
private static void addAttributeLore(ItemAttributeModifiers modifiers, NbtMapBuilder builder, String language) {
|
private static void addAttributeLore(ItemAttributeModifiers modifiers, BedrockItemBuilder builder, String language) {
|
||||||
CompoundTag displayTag = builder.get("display");
|
|
||||||
if (displayTag == null) {
|
|
||||||
displayTag = new CompoundTag("display");
|
|
||||||
}
|
|
||||||
ListTag lore = displayTag.get("Lore");
|
|
||||||
if (lore == null) {
|
|
||||||
lore = new ListTag("Lore");
|
|
||||||
}
|
|
||||||
|
|
||||||
// maps each slot to the modifiers applied when in such slot
|
// maps each slot to the modifiers applied when in such slot
|
||||||
Map<String, List<StringTag>> slotsToModifiers = new HashMap<>();
|
Map<ItemAttributeModifiers.EquipmentSlotGroup, List<String>> slotsToModifiers = new HashMap<>();
|
||||||
for (ItemAttributeModifiers.Entry entry : modifiers.getModifiers()) {
|
for (ItemAttributeModifiers.Entry entry : modifiers.getModifiers()) {
|
||||||
// convert the modifier tag to a lore entry
|
// convert the modifier tag to a lore entry
|
||||||
String loreEntry = attributeToLore(entry.getModifier(), language);
|
String loreEntry = attributeToLore(entry.getModifier(), language);
|
||||||
|
@ -220,23 +214,22 @@ public final class ItemTranslator {
|
||||||
continue; // invalid or failed
|
continue; // invalid or failed
|
||||||
}
|
}
|
||||||
|
|
||||||
StringTag loreTag = new StringTag("", loreEntry);
|
|
||||||
ItemAttributeModifiers.EquipmentSlotGroup slotGroup = entry.getSlot();
|
ItemAttributeModifiers.EquipmentSlotGroup slotGroup = entry.getSlot();
|
||||||
if (slotGroup == ItemAttributeModifiers.EquipmentSlotGroup.ANY) {
|
if (slotGroup == ItemAttributeModifiers.EquipmentSlotGroup.ANY) {
|
||||||
// modifier applies to all slots implicitly
|
// modifier applies to all slots implicitly
|
||||||
for (String slot : ALL_SLOTS) {
|
for (String slot : ALL_SLOTS) { // TODO SOMEONE LOOK HERE PLZ
|
||||||
slotsToModifiers.computeIfAbsent(slot, s -> new ArrayList<>()).add(loreTag);
|
//slotsToModifiers.computeIfAbsent(slot, s -> new ArrayList<>()).add(loreEntry);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// modifier applies to only the specified slot
|
// modifier applies to only the specified slot
|
||||||
slotsToModifiers.computeIfAbsent(slotGroup, s -> new ArrayList<>()).add(loreTag);
|
slotsToModifiers.computeIfAbsent(slotGroup, s -> new ArrayList<>()).add(loreEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate through the small array, not the map, so that ordering matches Java Edition
|
// iterate through the small array, not the map, so that ordering matches Java Edition
|
||||||
for (String slot : ALL_SLOTS) {
|
for (String slot : ALL_SLOTS) {
|
||||||
List<StringTag> modifiers = slotsToModifiers.get(slot);
|
List<String> modifierStrings = slotsToModifiers.get(slot);
|
||||||
if (modifiers == null || modifiers.isEmpty()) {
|
if (modifierStrings == null || modifierStrings.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,16 +239,13 @@ public final class ItemTranslator {
|
||||||
.color(NamedTextColor.GRAY)
|
.color(NamedTextColor.GRAY)
|
||||||
.append(Component.newline(), Component.translatable("item.modifiers." + slot))
|
.append(Component.newline(), Component.translatable("item.modifiers." + slot))
|
||||||
.build();
|
.build();
|
||||||
lore.add(new StringTag("", MessageTranslator.convertMessage(slotComponent, language)));
|
builder.getOrCreateLore().add(MessageTranslator.convertMessage(slotComponent, language));
|
||||||
|
|
||||||
// Then list all the modifiers when used in this slot
|
// Then list all the modifiers when used in this slot
|
||||||
for (StringTag modifier : modifiers) {
|
for (String modifier : modifierStrings) {
|
||||||
lore.add(modifier);
|
builder.getOrCreateLore().add(modifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
displayTag.put(lore);
|
|
||||||
nbt.put(displayTag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -294,29 +284,13 @@ public final class ItemTranslator {
|
||||||
return MessageTranslator.convertMessage(attributeComponent, language);
|
return MessageTranslator.convertMessage(attributeComponent, language);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CompoundTag addAdvancedTooltips(CompoundTag nbt, Item item, String language) {
|
private static void addAdvancedTooltips(DataComponents components, BedrockItemBuilder builder, Item item, String language) {
|
||||||
CompoundTag newNbt = nbt;
|
|
||||||
if (newNbt == null) {
|
|
||||||
newNbt = new CompoundTag("nbt");
|
|
||||||
CompoundTag display = new CompoundTag("display");
|
|
||||||
display.put(new ListTag("Lore"));
|
|
||||||
newNbt.put(display);
|
|
||||||
}
|
|
||||||
CompoundTag compoundTag = newNbt.get("display");
|
|
||||||
if (compoundTag == null) {
|
|
||||||
compoundTag = new CompoundTag("display");
|
|
||||||
}
|
|
||||||
ListTag listTag = compoundTag.get("Lore");
|
|
||||||
|
|
||||||
if (listTag == null) {
|
|
||||||
listTag = new ListTag("Lore");
|
|
||||||
}
|
|
||||||
int maxDurability = item.maxDamage();
|
int maxDurability = item.maxDamage();
|
||||||
|
|
||||||
if (maxDurability != 0) {
|
if (maxDurability != 0) {
|
||||||
Tag durabilityTag = newNbt.get("Damage");
|
Integer durabilityComponent = components.get(DataComponentType.DAMAGE);
|
||||||
if (durabilityTag instanceof IntTag) {
|
if (durabilityComponent != null) {
|
||||||
int durability = maxDurability - ((IntTag) durabilityTag).getValue();
|
int durability = maxDurability - durabilityComponent;
|
||||||
if (durability != maxDurability) {
|
if (durability != maxDurability) {
|
||||||
Component component = Component.text()
|
Component component = Component.text()
|
||||||
.resetStyle()
|
.resetStyle()
|
||||||
|
@ -325,24 +299,21 @@ public final class ItemTranslator {
|
||||||
Component.text(durability),
|
Component.text(durability),
|
||||||
Component.text(maxDurability)))
|
Component.text(maxDurability)))
|
||||||
.build();
|
.build();
|
||||||
listTag.add(new StringTag("", MessageTranslator.convertMessage(component, language)));
|
builder.getOrCreateLore().add(MessageTranslator.convertMessage(component, language));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listTag.add(new StringTag("", ChatColor.RESET + ChatColor.DARK_GRAY + item.javaIdentifier()));
|
builder.getOrCreateLore().add(ChatColor.RESET + ChatColor.DARK_GRAY + item.javaIdentifier());
|
||||||
if (nbt != null) {
|
if (components != null) {
|
||||||
Component component = Component.text()
|
Component component = Component.text()
|
||||||
.resetStyle()
|
.resetStyle()
|
||||||
.color(NamedTextColor.DARK_GRAY)
|
.color(NamedTextColor.DARK_GRAY)
|
||||||
.append(Component.translatable("item.nbt_tags",
|
.append(Component.translatable("item.nbt_tags", // TODO
|
||||||
Component.text(nbt.size())))
|
Component.text(components.getDataComponents().size())))
|
||||||
.build();
|
.build();
|
||||||
listTag.add(new StringTag("", MessageTranslator.convertMessage(component, language)));
|
builder.getOrCreateLore().add(MessageTranslator.convertMessage(component, language));
|
||||||
}
|
}
|
||||||
compoundTag.put(listTag);
|
|
||||||
newNbt.put(compoundTag);
|
|
||||||
return newNbt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -396,13 +367,13 @@ public final class ItemTranslator {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapping.getJavaItem().equals(Items.PLAYER_HEAD)) {
|
if (mapping.getJavaItem().equals(Items.PLAYER_HEAD)) {
|
||||||
CustomSkull customSkull = getCustomSkull(session, itemStack.getNbt());
|
CustomSkull customSkull = getCustomSkull(session, itemStack.getComponents());
|
||||||
if (customSkull != null) {
|
if (customSkull != null) {
|
||||||
itemDefinition = session.getItemMappings().getCustomBlockItemDefinitions().get(customSkull.getCustomBlockData());
|
itemDefinition = session.getItemMappings().getCustomBlockItemDefinitions().get(customSkull.getCustomBlockData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemDefinition definition = CustomItemTranslator.getCustomItem(itemStack, mapping);
|
ItemDefinition definition = CustomItemTranslator.getCustomItem(itemStack.getComponents(), mapping);
|
||||||
if (definition == null) {
|
if (definition == null) {
|
||||||
// No custom item
|
// No custom item
|
||||||
return itemDefinition;
|
return itemDefinition;
|
||||||
|
@ -533,65 +504,45 @@ public final class ItemTranslator {
|
||||||
/**
|
/**
|
||||||
* Translates the display name of the item
|
* Translates the display name of the item
|
||||||
* @param session the Bedrock client's session
|
* @param session the Bedrock client's session
|
||||||
* @param tag the tag to translate
|
* @param components the components to translate
|
||||||
* @param mapping the item entry, in case it requires translation
|
* @param mapping the item entry, in case it requires translation
|
||||||
*
|
|
||||||
* @return the new tag to use, should the current one be null
|
|
||||||
*/
|
*/
|
||||||
public static CompoundTag translateDisplayProperties(GeyserSession session, CompoundTag tag, ItemMapping mapping) {
|
public static String getCustomName(GeyserSession session, DataComponents components, ItemMapping mapping) {
|
||||||
return translateDisplayProperties(session, tag, mapping, 'f');
|
return getCustomName(session, components, mapping, 'f');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param translationColor if this item is not available on Java, the color that the new name should be.
|
* @param translationColor if this item is not available on Java, the color that the new name should be.
|
||||||
* Normally, this should just be white, but for shulker boxes this should be gray.
|
* Normally, this should just be white, but for shulker boxes this should be gray.
|
||||||
*/
|
*/
|
||||||
public static CompoundTag translateDisplayProperties(GeyserSession session, CompoundTag tag, ItemMapping mapping, char translationColor) {
|
public static String getCustomName(GeyserSession session, DataComponents components, ItemMapping mapping, char translationColor) {
|
||||||
boolean hasCustomName = false;
|
if (components != null) {
|
||||||
if (tag != null) {
|
// ItemStack#getHoverName as of 1.20.5
|
||||||
if (tag.get("display") instanceof CompoundTag display && display.get("Name") instanceof StringTag tagName) {
|
Component customName = components.get(DataComponentType.CUSTOM_NAME);
|
||||||
String name = tagName.getValue();
|
if (customName == null) {
|
||||||
|
customName = components.get(DataComponentType.ITEM_NAME);
|
||||||
// Get the translated name and prefix it with a reset char
|
}
|
||||||
name = MessageTranslator.convertMessageLenient(name, session.locale());
|
if (customName != null) {
|
||||||
|
// Get the translated name and prefix it with a reset char TODO test
|
||||||
// Add the new name tag
|
return MessageTranslator.convertMessage(customName, session.locale());
|
||||||
display.put(new StringTag("Name", name));
|
|
||||||
// Indicate that a custom name is present
|
|
||||||
hasCustomName = true;
|
|
||||||
|
|
||||||
// Add to the new root tag
|
|
||||||
tag.put(display);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasCustomName && mapping.hasTranslation()) {
|
if (mapping.hasTranslation()) {
|
||||||
// No custom name, but we need to localize the item's name
|
// No custom name, but we need to localize the item's name
|
||||||
if (tag == null) {
|
|
||||||
tag = new CompoundTag("");
|
|
||||||
}
|
|
||||||
CompoundTag display;
|
|
||||||
if (tag.get("display") instanceof CompoundTag oldDisplay) {
|
|
||||||
display = oldDisplay;
|
|
||||||
} else {
|
|
||||||
display = new CompoundTag("display");
|
|
||||||
// Add to the new root tag
|
|
||||||
tag.put(display);
|
|
||||||
}
|
|
||||||
|
|
||||||
String translationKey = mapping.getTranslationString();
|
String translationKey = mapping.getTranslationString();
|
||||||
// Reset formatting since Bedrock defaults to italics
|
// Reset formatting since Bedrock defaults to italics
|
||||||
display.put(new StringTag("Name", ChatColor.RESET + ChatColor.ESCAPE + translationColor + MinecraftLocale.getLocaleString(translationKey, session.locale())));
|
return ChatColor.RESET + ChatColor.ESCAPE + translationColor + MinecraftLocale.getLocaleString(translationKey, session.locale());
|
||||||
}
|
}
|
||||||
|
// No custom name
|
||||||
return tag;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates the custom model data of an item
|
* Translates the custom model data of an item
|
||||||
*/
|
*/
|
||||||
public static void translateCustomItem(CompoundTag nbt, ItemData.Builder builder, ItemMapping mapping) {
|
public static void translateCustomItem(DataComponents components, ItemData.Builder builder, ItemMapping mapping) {
|
||||||
ItemDefinition definition = CustomItemTranslator.getCustomItem(nbt, mapping);
|
ItemDefinition definition = CustomItemTranslator.getCustomItem(components, mapping);
|
||||||
if (definition != null) {
|
if (definition != null) {
|
||||||
builder.definition(definition);
|
builder.definition(definition);
|
||||||
builder.blockDefinition(null);
|
builder.blockDefinition(null);
|
||||||
|
@ -608,8 +559,12 @@ public final class ItemTranslator {
|
||||||
builder.blockDefinition(blockDefinition);
|
builder.blockDefinition(blockDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable CustomSkull getCustomSkull(GeyserSession session, CompoundTag nbt) {
|
private static @Nullable CustomSkull getCustomSkull(GeyserSession session, DataComponents components) {
|
||||||
if (nbt != null && nbt.contains("SkullOwner")) {
|
if (components == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
GameProfile profile = components.get(DataComponentType.PROFILE);
|
||||||
|
if (profile != null) {
|
||||||
if (!(nbt.get("SkullOwner") instanceof CompoundTag skullOwner)) {
|
if (!(nbt.get("SkullOwner") instanceof CompoundTag skullOwner)) {
|
||||||
// It's a username give up d:
|
// It's a username give up d:
|
||||||
return null;
|
return null;
|
||||||
|
@ -626,8 +581,8 @@ public final class ItemTranslator {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void translatePlayerHead(GeyserSession session, CompoundTag nbt, ItemData.Builder builder) {
|
private static void translatePlayerHead(GeyserSession session, DataComponents components, ItemData.Builder builder) {
|
||||||
CustomSkull customSkull = getCustomSkull(session, nbt);
|
CustomSkull customSkull = getCustomSkull(session, components);
|
||||||
if (customSkull != null) {
|
if (customSkull != null) {
|
||||||
CustomBlockData customBlockData = customSkull.getCustomBlockData();
|
CustomBlockData customBlockData = customSkull.getCustomBlockData();
|
||||||
ItemDefinition itemDefinition = session.getItemMappings().getCustomBlockItemDefinitions().get(customBlockData);
|
ItemDefinition itemDefinition = session.getItemMappings().getCustomBlockItemDefinitions().get(customBlockData);
|
||||||
|
@ -636,18 +591,4 @@ public final class ItemTranslator {
|
||||||
builder.blockDefinition(blockDefinition);
|
builder.blockDefinition(blockDefinition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the NBT of a Java item stack has the given hide flag.
|
|
||||||
*
|
|
||||||
* @param hideFlags the "HideFlags", which may not be null
|
|
||||||
* @param flagMask the flag to check for, as a bit mask
|
|
||||||
* @return true if the flag is present, false if not or if the tag value is not a number
|
|
||||||
*/
|
|
||||||
private static boolean hasFlagPresent(Tag hideFlags, byte flagMask) {
|
|
||||||
if (hideFlags.getValue() instanceof Number flags) {
|
|
||||||
return (flags.byteValue() & flagMask) == flagMask;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue