1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-30 12:19:10 +00:00

Some cleanups and stuff

This commit is contained in:
Eclipse
2025-03-25 20:37:14 +00:00
parent 4e06608f84
commit 413be6c8b8
3 changed files with 13 additions and 19 deletions

View File

@@ -69,10 +69,10 @@ public class ComponentHashers {
static {
register(DataComponentTypes.CUSTOM_DATA, MinecraftHasher.NBT_MAP);
register(DataComponentTypes.MAX_STACK_SIZE);
register(DataComponentTypes.MAX_DAMAGE);
register(DataComponentTypes.DAMAGE);
register(DataComponentTypes.UNBREAKABLE);
registerInt(DataComponentTypes.MAX_STACK_SIZE);
registerInt(DataComponentTypes.MAX_DAMAGE);
registerInt(DataComponentTypes.DAMAGE);
registerUnit(DataComponentTypes.UNBREAKABLE);
// TODO custom name, component
// TODO item name, component
@@ -97,7 +97,7 @@ public class ComponentHashers {
.optional("hide_tooltip", MinecraftHasher.BOOL, TooltipDisplay::hideTooltip, false)
.optionalList("hidden_components", RegistryHasher.DATA_COMPONENT_TYPE, TooltipDisplay::hiddenComponents));
register(DataComponentTypes.REPAIR_COST);
registerInt(DataComponentTypes.REPAIR_COST);
register(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, MinecraftHasher.BOOL);
//register(DataComponentTypes.INTANGIBLE_PROJECTILE); // TODO MCPL is wrong
@@ -142,16 +142,16 @@ public class ComponentHashers {
registerMap(DataComponentTypes.REPAIRABLE, builder -> builder
.accept("items", RegistryHasher.ITEM.holderSet(), Function.identity()));
register(DataComponentTypes.GLIDER);
registerUnit(DataComponentTypes.GLIDER);
register(DataComponentTypes.TOOLTIP_STYLE, MinecraftHasher.KEY);
registerMap(DataComponentTypes.DEATH_PROTECTION, builder -> builder); // TODO consume effect needs identifier in MCPL
registerMap(DataComponentTypes.BLOCKS_ATTACKS, builder -> builder); // TODO needs damage types, add a way to cache identifiers without reading objects in registrycache
register(DataComponentTypes.STORED_ENCHANTMENTS, MinecraftHasher.map(RegistryHasher.ENCHANTMENT, MinecraftHasher.INT).convert(ItemEnchantments::getEnchantments)); // TODO duplicate code?
register(DataComponentTypes.DYED_COLOR);
register(DataComponentTypes.MAP_COLOR);
register(DataComponentTypes.MAP_ID);
registerInt(DataComponentTypes.DYED_COLOR);
registerInt(DataComponentTypes.MAP_COLOR);
registerInt(DataComponentTypes.MAP_ID);
register(DataComponentTypes.MAP_DECORATIONS, MinecraftHasher.NBT_MAP);
// TODO charged projectiles also need the recursion™
@@ -166,11 +166,11 @@ public class ComponentHashers {
register(DataComponentTypes.POTION_DURATION_SCALE, MinecraftHasher.FLOAT);
}
private static void register(DataComponentType<Unit> component) {
private static void registerUnit(DataComponentType<Unit> component) {
register(component, MinecraftHasher.UNIT);
}
private static void register(IntComponentType component) {
private static void registerInt(IntComponentType component) {
register(component, MinecraftHasher.INT);
}
@@ -193,6 +193,7 @@ public class ComponentHashers {
return hasher.hash(value, new MinecraftHashEncoder(session));
}
// TODO better hashing, at the moment this is just called when the player is spawned
public static void testHashing(GeyserSession session) {
// Hashed values generated by vanilla Java

View File

@@ -80,7 +80,7 @@ public interface MinecraftHasher<T> {
.optionalNullable("speed", MinecraftHasher.FLOAT, ToolData.Rule::getSpeed)
.optionalNullable("correct_for_drops", MinecraftHasher.BOOL, ToolData.Rule::getCorrectForDrops));
MinecraftHasher<EquipmentSlot> EQUIPMENT_SLOT = fromEnum();
MinecraftHasher<EquipmentSlot> EQUIPMENT_SLOT = fromEnum(); // FIXME MCPL enum constants aren't right
MinecraftHasher<MobEffectInstance> MOB_EFFECT_INSTANCE = mapBuilder(builder -> builder
.accept("id", RegistryHasher.EFFECT, MobEffectInstance::getEffect)

View File

@@ -75,13 +75,7 @@ public final class DataComponentRegistryPopulator {
byte[] bytes = Base64.getDecoder().decode(encodedValue);
ByteBuf buf = Unpooled.wrappedBuffer(bytes);
int varInt = MinecraftTypes.readVarInt(buf);
//System.out.println("int: " + varInt + " " + componentEntry.getKey());
DataComponentType<?> dataComponentType = DataComponentTypes.from(varInt);
if (dataComponentType == DataComponentTypes.ENCHANTMENTS
|| dataComponentType == DataComponentTypes.STORED_ENCHANTMENTS
|| dataComponentType == DataComponentTypes.JUKEBOX_PLAYABLE) {
continue; // TODO Broken reading in MCPL
}
DataComponent<?, ?> dataComponent = dataComponentType.readDataComponent(buf);
map.put(dataComponentType, dataComponent);
@@ -90,7 +84,6 @@ public final class DataComponentRegistryPopulator {
defaultComponents.add(new DataComponents(ImmutableMap.copyOf(map)));
}
} catch (Exception e) {
// TODO 1.21.5 enchantment reading is broken
throw new AssertionError("Unable to load or parse components", e);
}