mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Add glint generation
This commit is contained in:
parent
723ede1ed6
commit
8fe1b8f818
3 changed files with 34 additions and 8 deletions
|
|
@ -1205,7 +1205,7 @@ public final class Items {
|
|||
public static final Item SHULKER_SHELL = register(new Item("shulker_shell", builder()));
|
||||
public static final Item IRON_NUGGET = register(new Item("iron_nugget", builder()));
|
||||
public static final Item KNOWLEDGE_BOOK = register(new Item("knowledge_book", builder().stackSize(1).rarity(Rarity.EPIC)));
|
||||
public static final Item DEBUG_STICK = register(new Item("debug_stick", builder().stackSize(1).rarity(Rarity.EPIC)));
|
||||
public static final Item DEBUG_STICK = register(new Item("debug_stick", builder().stackSize(1).rarity(Rarity.EPIC).glint(true)));
|
||||
public static final Item MUSIC_DISC_13 = register(new Item("music_disc_13", builder().stackSize(1).rarity(Rarity.RARE)));
|
||||
public static final Item MUSIC_DISC_CAT = register(new Item("music_disc_cat", builder().stackSize(1).rarity(Rarity.RARE)));
|
||||
public static final Item MUSIC_DISC_BLOCKS = register(new Item("music_disc_blocks", builder().stackSize(1).rarity(Rarity.RARE)));
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ public class Item {
|
|||
private final int attackDamage;
|
||||
private final int maxDamage;
|
||||
private final Rarity rarity;
|
||||
private final boolean glint;
|
||||
|
||||
public Item(String javaIdentifier, Builder builder) {
|
||||
this.javaIdentifier = MinecraftKey.key(javaIdentifier).asString().intern();
|
||||
|
|
@ -72,6 +73,7 @@ public class Item {
|
|||
this.maxDamage = builder.maxDamage;
|
||||
this.attackDamage = builder.attackDamage;
|
||||
this.rarity = builder.rarity;
|
||||
this.glint = builder.glint;
|
||||
}
|
||||
|
||||
public String javaIdentifier() {
|
||||
|
|
@ -94,7 +96,13 @@ public class Item {
|
|||
return stackSize;
|
||||
}
|
||||
|
||||
public Rarity rarity() { return rarity; }
|
||||
public Rarity rarity() {
|
||||
return rarity;
|
||||
}
|
||||
|
||||
public boolean glint() {
|
||||
return glint;
|
||||
}
|
||||
|
||||
public boolean isValidRepairItem(Item other) {
|
||||
return false;
|
||||
|
|
@ -117,10 +125,6 @@ public class Item {
|
|||
return builder;
|
||||
}
|
||||
|
||||
public NbtMap build(GeyserSession session, BedrockItemBuilder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public @NonNull GeyserItemStack translateToJava(@NonNull ItemData itemData, @NonNull ItemMapping mapping, @NonNull ItemMappings mappings) {
|
||||
return GeyserItemStack.of(javaId, itemData.getCount());
|
||||
}
|
||||
|
|
@ -285,6 +289,7 @@ public class Item {
|
|||
private int maxDamage;
|
||||
private int attackDamage;
|
||||
private Rarity rarity = Rarity.COMMON;
|
||||
private boolean glint = false;
|
||||
|
||||
public Builder stackSize(int stackSize) {
|
||||
this.stackSize = stackSize;
|
||||
|
|
@ -307,6 +312,11 @@ public class Item {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder glint(boolean glintOverride) {
|
||||
this.glint = glintOverride;
|
||||
return this;
|
||||
}
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,9 @@ 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.Nullable;
|
||||
import org.cloudburstmc.nbt.NbtList;
|
||||
import org.cloudburstmc.nbt.NbtMap;
|
||||
import org.cloudburstmc.nbt.NbtMapBuilder;
|
||||
import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition;
|
||||
import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition;
|
||||
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
||||
|
|
@ -146,14 +148,20 @@ public final class ItemTranslator {
|
|||
}
|
||||
|
||||
Rarity rarity = javaItem.rarity();
|
||||
boolean enchantmentGlint = javaItem.glint();
|
||||
if (components != null) {
|
||||
Integer rarityIndex = components.get(DataComponentType.RARITY);
|
||||
if (rarityIndex != null) {
|
||||
rarity = Rarity.fromId(rarityIndex);
|
||||
}
|
||||
Boolean enchantmentGlintOverride = components.get(DataComponentType.ENCHANTMENT_GLINT_OVERRIDE);
|
||||
if (enchantmentGlintOverride != null) {
|
||||
enchantmentGlint = enchantmentGlintOverride;
|
||||
}
|
||||
}
|
||||
|
||||
String customName = getCustomName(session, components, bedrockItem, rarity.getColor());
|
||||
GeyserImpl.getInstance().getLogger().info("custom name: " + customName + " rarity: " + rarity.getName());
|
||||
if (customName != null) {
|
||||
nbtBuilder.setCustomName(customName);
|
||||
}
|
||||
|
|
@ -170,9 +178,17 @@ public final class ItemTranslator {
|
|||
addAdvancedTooltips(components, nbtBuilder, javaItem, session.locale());
|
||||
}
|
||||
|
||||
// Add enchantment override. We can't remove it - enchantments would stop showing - but we can add it.
|
||||
if (enchantmentGlint) {
|
||||
NbtMapBuilder nbtMapBuilder = nbtBuilder.getOrCreateNbt();
|
||||
if (!nbtMapBuilder.containsKey("ench")) {
|
||||
nbtMapBuilder.put("ench", NbtList.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
ItemData.Builder builder = javaItem.translateToBedrock(count, components, bedrockItem, session.getItemMappings());
|
||||
// Finalize the Bedrock NBT
|
||||
builder.tag(javaItem.build(session, nbtBuilder));
|
||||
builder.tag(nbtBuilder.build());
|
||||
if (bedrockItem.isBlock()) {
|
||||
CustomBlockData customBlockData = BlockRegistries.CUSTOM_BLOCK_ITEM_OVERRIDES.getOrDefault(
|
||||
bedrockItem.getJavaItem().javaIdentifier(), null);
|
||||
|
|
@ -430,7 +446,7 @@ public final class ItemTranslator {
|
|||
// No custom name, but we need to localize the item's name
|
||||
String translationKey = mapping.getTranslationString();
|
||||
// Reset formatting since Bedrock defaults to italics
|
||||
return ChatColor.RESET + ChatColor.ESCAPE + translationColor + MinecraftLocale.getLocaleString(translationKey, session.locale());
|
||||
return ChatColor.ESCAPE + translationColor + MinecraftLocale.getLocaleString(translationKey, session.locale());
|
||||
}
|
||||
// No custom name
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue