ominous banners - this really isn't ideal

This commit is contained in:
onebeastchris 2024-04-29 23:19:18 +02:00
parent 8b7b8cdffd
commit 5d3630cf23
5 changed files with 52 additions and 20 deletions

View file

@ -244,8 +244,8 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
if (Boolean.parseBoolean(System.getProperty("Geyser.UseDirectAdapters", "true"))) {
try {
String name = Bukkit.getServer().getClass().getPackage().getName();
String nmsVersion = name.substring(name.lastIndexOf('.') + 1);
String version = Bukkit.getBukkitVersion().split("-")[0];
String nmsVersion = "v" + version.replace(".", "_");
SpigotAdapters.registerWorldAdapter(nmsVersion);
if (isViaVersion && isViaVersionNeeded()) {
this.geyserWorldManager = new GeyserSpigotLegacyNativeWorldManager(this);

View file

@ -45,7 +45,7 @@ public enum BannerPattern {
STRIPE_MIDDLE("ms"),
STRIPE_DOWNRIGHT("drs"),
STRIPE_DOWNLEFT("dls"),
SMALL_STRIPES("ss"),
STRIPE_SMALL("ss"),
CROSS("cr"),
STRAIGHT_CROSS("sc"),
TRIANGLE_BOTTOM("bt"),
@ -53,15 +53,15 @@ public enum BannerPattern {
TRIANGLES_BOTTOM("bts"),
TRIANGLES_TOP("tts"),
DIAGONAL_LEFT("ld"),
DIAGONAL_UP_RIGHT("rd"),
DIAGONAL_UP_LEFT("lud"),
DIAGONAL_RIGHT("rud"),
CIRCLE("mc"),
RHOMBUS("mr"),
DIAGONAL_RIGHT("rd"),
DIAGONAL_LEFT_MIRROR("lud"),
DIAGONAL_RIGHT_MIRROR("rud"),
CIRCLE_MIDDLE("mc"),
RHOMBUS_MIDDLE("mr"),
HALF_VERTICAL("vh"),
HALF_HORIZONTAL("hh"),
HALF_VERTICAL_RIGHT("vhr"),
HALF_HORIZONTAL_BOTTOM("hhb"),
HALF_VERTICAL_MIRROR("vhr"),
HALF_HORIZONTAL_MIRROR("hhb"),
BORDER("bo"),
CURLY_BORDER("cbo"),
GRADIENT("gra"),

View file

@ -26,18 +26,26 @@
package org.geysermc.geyser.item.type;
import it.unimi.dsi.fastutil.Pair;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.cloudburstmc.nbt.NbtList;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtType;
import org.cloudburstmc.protocol.common.util.Int2ObjectBiMap;
import org.geysermc.geyser.inventory.item.BannerPattern;
import org.geysermc.geyser.inventory.item.DyeColor;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.text.MinecraftLocale;
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
import org.geysermc.mcprotocollib.protocol.data.game.Holder;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.BannerPatternLayer;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponentType;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.Unit;
import java.util.ArrayList;
import java.util.List;
@ -56,13 +64,13 @@ public class BannerItem extends BlockItem {
static {
// Construct what an ominous banner is supposed to look like
OMINOUS_BANNER_PATTERN = List.of(
Pair.of(BannerPattern.RHOMBUS, DyeColor.CYAN),
Pair.of(BannerPattern.RHOMBUS_MIDDLE, DyeColor.CYAN),
Pair.of(BannerPattern.STRIPE_BOTTOM, DyeColor.LIGHT_GRAY),
Pair.of(BannerPattern.STRIPE_CENTER, DyeColor.GRAY),
Pair.of(BannerPattern.BORDER, DyeColor.LIGHT_GRAY),
Pair.of(BannerPattern.STRIPE_MIDDLE, DyeColor.BLACK),
Pair.of(BannerPattern.HALF_HORIZONTAL, DyeColor.LIGHT_GRAY),
Pair.of(BannerPattern.CIRCLE, DyeColor.LIGHT_GRAY),
Pair.of(BannerPattern.CIRCLE_MIDDLE, DyeColor.LIGHT_GRAY),
Pair.of(BannerPattern.BORDER, DyeColor.BLACK)
);
@ -171,14 +179,13 @@ public class BannerItem extends BlockItem {
* @return The Java edition format pattern layer
*/
public static BannerPatternLayer getJavaBannerPattern(GeyserSession session, NbtMap pattern) {
return null; // TODO
/*Int2ObjectBiMap<BannerPattern> registry = session.getRegistryCache().bannerPatterns();
Int2ObjectBiMap<BannerPattern> registry = session.getRegistryCache().bannerPatterns();
BannerPattern bannerPattern = BannerPattern.getByBedrockIdentifier(pattern.getString("Pattern"));
DyeColor dyeColor = DyeColor.getById(15 - pattern.getInt("Color"));
if (bannerPattern != null && dyeColor != null && registry.containsValue(bannerPattern)) {
return new BannerPatternLayer(Holder.ofId(registry.get(bannerPattern)), dyeColor.ordinal());
}
return null;*/
return null;
}
public BannerItem(String javaIdentifier, Builder builder) {
@ -196,13 +203,22 @@ public class BannerItem extends BlockItem {
}
@Override
public void translateNbtToJava(@NonNull NbtMap bedrockTag, @NonNull DataComponents components, @NonNull ItemMapping mapping) { // TODO
public void translateNbtToJava(@NonNull NbtMap bedrockTag, @NonNull DataComponents components, @NonNull ItemMapping mapping) {
super.translateNbtToJava(bedrockTag, components, mapping);
if (bedrockTag.getInt("Type") == 1) {
// Ominous banner pattern
// TODO more registry stuff
//components.put(DataComponentType.BANNER_PATTERNS);
List<BannerPatternLayer> patternLayers = new ArrayList<>();
for (Pair<BannerPattern, DyeColor> pair : OMINOUS_BANNER_PATTERN) {
patternLayers.add(new BannerPatternLayer(Holder.ofId(pair.left().ordinal()), pair.right().ordinal()));
}
components.put(DataComponentType.BANNER_PATTERNS, patternLayers);
components.put(DataComponentType.HIDE_ADDITIONAL_TOOLTIP, Unit.INSTANCE);
components.put(DataComponentType.ITEM_NAME, Component.text(
MinecraftLocale.getLocaleString("block.minecraft.ominous_banner", GeyserLocale.getDefaultLocale())
).style(Style.style(TextColor.color(16755200)))
);
}
// Bedrock's creative inventory does not support other patterns as of 1.20.5
}

View file

@ -579,6 +579,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
private final GeyserEntityData entityData;
@Getter
private MinecraftProtocol protocol;
public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop eventLoop) {

View file

@ -34,6 +34,7 @@ import lombok.Getter;
import lombok.experimental.Accessors;
import org.cloudburstmc.protocol.bedrock.data.TrimMaterial;
import org.cloudburstmc.protocol.bedrock.data.TrimPattern;
import org.cloudburstmc.protocol.common.util.Int2ObjectBiMap;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.entity.type.living.animal.tameable.WolfEntity;
import org.geysermc.geyser.inventory.item.BannerPattern;
@ -70,7 +71,7 @@ public final class RegistryCache {
register("trim_material", cache -> cache.trimMaterials, TrimRecipe::readTrimMaterial);
register("trim_pattern", cache -> cache.trimPatterns, TrimRecipe::readTrimPattern);
register("worldgen/biome", (cache, array) -> cache.biomeTranslations = array, BiomeTranslator::loadServerBiome);
register("banner_pattern", cache -> cache.bannerPatterns, ($, entry) -> BannerPattern.getByJavaIdentifier(entry.getId()));
registerBannerRegistry(($, entry) -> BannerPattern.getByJavaIdentifier(entry.getId()));
register("wolf_variant", cache -> cache.wolfVariants, ($, entry) -> WolfEntity.WolfVariant.getByJavaIdentifier(entry.getId()));
}
@ -89,7 +90,7 @@ public final class RegistryCache {
private final Int2ObjectMap<TrimMaterial> trimMaterials = new Int2ObjectOpenHashMap<>();
private final Int2ObjectMap<TrimPattern> trimPatterns = new Int2ObjectOpenHashMap<>();
private final Int2ObjectMap<BannerPattern> bannerPatterns = new Int2ObjectOpenHashMap<>();
private Int2ObjectBiMap<BannerPattern> bannerPatterns = new Int2ObjectBiMap<>();
private final Int2ObjectMap<WolfEntity.WolfVariant> wolfVariants = new Int2ObjectOpenHashMap<>();
public RegistryCache(GeyserSession session) {
@ -108,6 +109,20 @@ public final class RegistryCache {
}
}
private static <T> void registerBannerRegistry(BiFunction<GeyserSession, RegistryEntry, T> reader) {
REGISTRIES.put("minecraft:banner_pattern", ((registryCache, entries) -> {
// Clear each local cache every time a new registry entry is given to us
// (e.g. proxy server switches)
registryCache.bannerPatterns = new Int2ObjectBiMap<>();
for (int i = 0; i < entries.size(); i++) {
RegistryEntry entry = entries.get(i);
// This is what Geyser wants to keep as a value for this registry.
T cacheEntry = reader.apply(registryCache.session, entry);
registryCache.bannerPatterns.put(i, (BannerPattern) cacheEntry);
}
}));
}
/**
* @param registry the Java registry resource location, without the "minecraft:" prefix.
* @param localCacheFunction which local field in RegistryCache are we caching entries for this registry?