mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix some issues, still broken
This commit is contained in:
parent
8c8c46bf92
commit
7c9842e597
2 changed files with 17 additions and 17 deletions
|
@ -58,10 +58,11 @@ public final class TagCache {
|
||||||
|
|
||||||
public void loadPacket(GeyserSession session, ClientboundUpdateTagsPacket packet) {
|
public void loadPacket(GeyserSession session, ClientboundUpdateTagsPacket packet) {
|
||||||
Map<Key, Map<Key, int[]>> allTags = packet.getTags();
|
Map<Key, Map<Key, int[]>> allTags = packet.getTags();
|
||||||
|
int tagsLoading = (int) allTags.keySet().stream().filter(TagRegistry::shouldLoad).count();
|
||||||
GeyserLogger logger = session.getGeyser().getLogger();
|
GeyserLogger logger = session.getGeyser().getLogger();
|
||||||
|
|
||||||
this.tagIndexMaps = new ArrayList<>(allTags.size());
|
this.tagIndexMaps = new ArrayList<>(tagsLoading);
|
||||||
this.tags = new int[allTags.size()][][];
|
this.tags = new int[tagsLoading][][];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Key registryKey : allTags.keySet()) {
|
for (Key registryKey : allTags.keySet()) {
|
||||||
|
@ -91,7 +92,7 @@ public final class TagCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
int[][] registryTagsArray = new int[0][];
|
int[][] registryTagsArray = new int[0][];
|
||||||
this.tagIndexMaps.set(i, loadTags(registryTags, registryTagsArray, registry));
|
this.tagIndexMaps.add(loadTags(registryTags, registryTagsArray, registry));
|
||||||
this.tags[i] = registryTagsArray;
|
this.tags[i] = registryTagsArray;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -99,22 +100,18 @@ public final class TagCache {
|
||||||
|
|
||||||
private Object2IntMap<Key> loadTags(Map<Key, int[]> packetTags, int[][] tags, TagRegistry registry) {
|
private Object2IntMap<Key> loadTags(Map<Key, int[]> packetTags, int[][] tags, TagRegistry registry) {
|
||||||
List<Key> vanillaTagKeys = List.copyOf(registry.getVanillaTags().keySet());
|
List<Key> vanillaTagKeys = List.copyOf(registry.getVanillaTags().keySet());
|
||||||
int nonVanillaTagAmount = (int) packetTags.keySet().stream().filter(tag -> !vanillaTagKeys.contains(tag)).count();
|
List<Key> nonVanillaTagKeys = packetTags.keySet().stream().filter(tag -> !vanillaTagKeys.contains(tag)).toList();
|
||||||
|
|
||||||
List<int[]> tagsBuilder = new ArrayList<>(vanillaTagKeys.size() + nonVanillaTagAmount);
|
List<int[]> tagsBuilder = new ArrayList<>(vanillaTagKeys.size() + nonVanillaTagKeys.size());
|
||||||
Object2IntMap<Key> tagIndexMap = new Object2IntOpenHashMap<>();
|
Object2IntMap<Key> tagIndexMap = new Object2IntOpenHashMap<>();
|
||||||
|
|
||||||
int nonVanillaTagIndex = vanillaTagKeys.size();
|
for (Key vanillaTagKey : registry.getVanillaTags().keySet()) {
|
||||||
for (Map.Entry<Key, int[]> tag : packetTags.entrySet()) {
|
tagsBuilder.add(packetTags.getOrDefault(vanillaTagKey, new int[0]));
|
||||||
int id;
|
}
|
||||||
if (vanillaTagKeys.contains(tag.getKey())) {
|
|
||||||
id = vanillaTagKeys.indexOf(tag.getKey());
|
for (Key nonVanillaTagKey : nonVanillaTagKeys) {
|
||||||
} else {
|
tagIndexMap.put(nonVanillaTagKey, tagsBuilder.size());
|
||||||
id = nonVanillaTagIndex;
|
tagsBuilder.add(packetTags.get(nonVanillaTagKey));
|
||||||
nonVanillaTagIndex++;
|
|
||||||
}
|
|
||||||
tagsBuilder.set(id, tag.getValue());
|
|
||||||
tagIndexMap.put(tag.getKey(), id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tagsBuilder.toArray(tags);
|
tagsBuilder.toArray(tags);
|
||||||
|
@ -133,7 +130,6 @@ public final class TagCache {
|
||||||
* @return true if the item tag is present and contains this item stack's Java ID.
|
* @return true if the item tag is present and contains this item stack's Java ID.
|
||||||
*/
|
*/
|
||||||
public boolean is(Tag tag, GeyserItemStack itemStack) {
|
public boolean is(Tag tag, GeyserItemStack itemStack) {
|
||||||
assert tag.registry() == TagRegistry.ITEM;
|
|
||||||
return is(tag, itemStack.asItem());
|
return is(tag, itemStack.asItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@ public enum TagRegistry {
|
||||||
this.vanillaTags = vanillaTags;
|
this.vanillaTags = vanillaTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean shouldLoad(Key registryKey) {
|
||||||
|
return valueOf(registryKey) != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static TagRegistry valueOf(Key registryKey) {
|
public static TagRegistry valueOf(Key registryKey) {
|
||||||
for (TagRegistry registry : TagRegistry.values()) {
|
for (TagRegistry registry : TagRegistry.values()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue