mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-12-19 14:59:27 +00:00
Fix vault block entity component translation, minor cleanups (#5688)
This commit is contained in:
@@ -42,8 +42,7 @@ import java.util.Set;
|
|||||||
* @param description only populated if {@link #bedrockEnchantment()} is null.
|
* @param description only populated if {@link #bedrockEnchantment()} is null.
|
||||||
* @param anvilCost also as a rarity multiplier
|
* @param anvilCost also as a rarity multiplier
|
||||||
*/
|
*/
|
||||||
public record Enchantment(String identifier,
|
public record Enchantment(Set<EnchantmentComponent> effects,
|
||||||
Set<EnchantmentComponent> effects,
|
|
||||||
GeyserHolderSet<Item> supportedItems,
|
GeyserHolderSet<Item> supportedItems,
|
||||||
int maxLevel,
|
int maxLevel,
|
||||||
String description,
|
String description,
|
||||||
@@ -66,8 +65,7 @@ public record Enchantment(String identifier,
|
|||||||
|
|
||||||
String description = bedrockEnchantment == null ? MessageTranslator.deserializeDescription(context.session(), data) : null;
|
String description = bedrockEnchantment == null ? MessageTranslator.deserializeDescription(context.session(), data) : null;
|
||||||
|
|
||||||
return new Enchantment(context.id().asString(), effects, supportedItems, maxLevel,
|
return new Enchantment(effects, supportedItems, maxLevel, description, anvilCost, exclusiveSet, bedrockEnchantment);
|
||||||
description, anvilCost, exclusiveSet, bedrockEnchantment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<EnchantmentComponent> readEnchantmentComponents(NbtMap effects) {
|
private static Set<EnchantmentComponent> readEnchantmentComponents(NbtMap effects) {
|
||||||
|
|||||||
@@ -71,6 +71,11 @@ public interface JavaRegistry<T> {
|
|||||||
*/
|
*/
|
||||||
void reset(List<RegistryEntryData<T>> values);
|
void reset(List<RegistryEntryData<T>> values);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All keys of this registry, as a list.
|
||||||
|
*/
|
||||||
|
List<Key> keys();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All values of this registry, as a list.
|
* All values of this registry, as a list.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ public class SimpleJavaRegistry<T> implements JavaRegistry<T> {
|
|||||||
this.values.trim();
|
this.values.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Key> keys() {
|
||||||
|
return this.values.stream().map(RegistryEntryData::key).toList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<T> values() {
|
public List<T> values() {
|
||||||
return this.values.stream().map(RegistryEntryData::data).toList();
|
return this.values.stream().map(RegistryEntryData::data).toList();
|
||||||
|
|||||||
@@ -25,8 +25,8 @@
|
|||||||
|
|
||||||
package org.geysermc.geyser.translator.level.block.entity;
|
package org.geysermc.geyser.translator.level.block.entity;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||||
import it.unimi.dsi.fastutil.longs.LongList;
|
import it.unimi.dsi.fastutil.longs.LongList;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
@@ -37,13 +37,13 @@ import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
|||||||
import org.cloudburstmc.protocol.common.util.TriConsumer;
|
import org.cloudburstmc.protocol.common.util.TriConsumer;
|
||||||
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
||||||
import org.geysermc.geyser.inventory.item.Potion;
|
import org.geysermc.geyser.inventory.item.Potion;
|
||||||
import org.geysermc.geyser.item.enchantment.Enchantment;
|
|
||||||
import org.geysermc.geyser.level.block.type.BlockState;
|
import org.geysermc.geyser.level.block.type.BlockState;
|
||||||
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.session.cache.registry.JavaRegistries;
|
import org.geysermc.geyser.session.cache.registry.JavaRegistries;
|
||||||
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||||
import org.geysermc.geyser.translator.item.ItemTranslator;
|
import org.geysermc.geyser.translator.item.ItemTranslator;
|
||||||
|
import org.geysermc.geyser.util.MinecraftKey;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
|
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentTypes;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||||
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemEnchantments;
|
import org.geysermc.mcprotocollib.protocol.data.game.item.component.ItemEnchantments;
|
||||||
@@ -52,6 +52,7 @@ import org.geysermc.mcprotocollib.protocol.data.game.level.block.BlockEntityType
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@BlockEntity(type = BlockEntityType.VAULT)
|
@BlockEntity(type = BlockEntityType.VAULT)
|
||||||
@@ -131,20 +132,14 @@ public class VaultBlockEntityTranslator extends BlockEntityTranslator {
|
|||||||
// The goal is to just translate the basics so clients know what potion is roughly present, and that any enchantment even exists.
|
// The goal is to just translate the basics so clients know what potion is roughly present, and that any enchantment even exists.
|
||||||
private static final Map<String, TriConsumer<GeyserSession, NbtMap, DataComponents>> DATA_COMPONENT_DECODERS = Map.of(
|
private static final Map<String, TriConsumer<GeyserSession, NbtMap, DataComponents>> DATA_COMPONENT_DECODERS = Map.of(
|
||||||
"minecraft:potion_contents", (session, tag, components) -> {
|
"minecraft:potion_contents", (session, tag, components) -> {
|
||||||
String potionId = tag.getString("potion");
|
// Can only translate built-in potions, potions with custom colours don't work
|
||||||
Potion potion = Potion.getByJavaIdentifier(potionId);
|
Optional.ofNullable(tag.getString("potion")).map(Potion::getByJavaIdentifier)
|
||||||
components.put(DataComponentTypes.POTION_CONTENTS, potion.toComponent());
|
.ifPresent(potion -> components.put(DataComponentTypes.POTION_CONTENTS, potion.toComponent()));
|
||||||
},
|
},
|
||||||
"minecraft:enchantments", (session, tag, components) -> { // Enchanted books already have glint. Translating them doesn't matter.
|
"minecraft:enchantments", (session, tag, components) -> { // Enchanted books already have glint. Translating them doesn't matter.
|
||||||
NbtMap levels = tag.getCompound("levels");
|
Int2IntMap enchantments = new Int2IntOpenHashMap(tag.size());
|
||||||
List<Enchantment> enchantmentRegistry = session.getRegistryCache().registry(JavaRegistries.ENCHANTMENT).values();
|
for (Map.Entry<String, Object> entry : tag.entrySet()) {
|
||||||
Int2ObjectMap<Integer> enchantments = new Int2ObjectOpenHashMap<>(levels.size());
|
enchantments.put(JavaRegistries.ENCHANTMENT.networkId(session, MinecraftKey.key(entry.getKey())), (int) entry.getValue());
|
||||||
for (Map.Entry<String, Object> entry : levels.entrySet()) {
|
|
||||||
for (int i = 0; i < enchantmentRegistry.size(); i++) {
|
|
||||||
if (enchantmentRegistry.get(i).identifier().equals(entry.getKey())) {
|
|
||||||
enchantments.put(i, (Integer) entry.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
components.put(DataComponentTypes.ENCHANTMENTS, new ItemEnchantments(enchantments));
|
components.put(DataComponentTypes.ENCHANTMENTS, new ItemEnchantments(enchantments));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ import org.geysermc.geyser.GeyserImpl;
|
|||||||
import org.geysermc.geyser.api.event.java.ServerDefineCommandsEvent;
|
import org.geysermc.geyser.api.event.java.ServerDefineCommandsEvent;
|
||||||
import org.geysermc.geyser.api.util.PlatformType;
|
import org.geysermc.geyser.api.util.PlatformType;
|
||||||
import org.geysermc.geyser.command.CommandRegistry;
|
import org.geysermc.geyser.command.CommandRegistry;
|
||||||
import org.geysermc.geyser.item.enchantment.Enchantment;
|
|
||||||
import org.geysermc.geyser.registry.BlockRegistries;
|
import org.geysermc.geyser.registry.BlockRegistries;
|
||||||
import org.geysermc.geyser.registry.Registries;
|
import org.geysermc.geyser.registry.Registries;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
@@ -369,8 +368,7 @@ public class JavaCommandsTranslator extends PacketTranslator<ClientboundCommands
|
|||||||
if (enchantments != null) {
|
if (enchantments != null) {
|
||||||
return enchantments;
|
return enchantments;
|
||||||
}
|
}
|
||||||
return (enchantments = session.getRegistryCache().registry(JavaRegistries.ENCHANTMENT).values().stream()
|
return (enchantments = session.getRegistryCache().registry(JavaRegistries.ENCHANTMENT).keys().stream().map(Key::asString).toArray(String[]::new));
|
||||||
.map(Enchantment::identifier).toArray(String[]::new));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] getEntityTypes() {
|
private String[] getEntityTypes() {
|
||||||
|
|||||||
Reference in New Issue
Block a user