mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix banners on shields
This commit is contained in:
parent
82123aecf1
commit
e8c1c2218f
2 changed files with 39 additions and 35 deletions
|
@ -113,6 +113,31 @@ public class BannerItem extends BlockItem {
|
|||
return new NbtList<>(NbtType.COMPOUND, tagsList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Java item component for banners into Bedrock item NBT.
|
||||
*/
|
||||
static void convertBannerPattern(GeyserSession session, List<BannerPatternLayer> patterns, BedrockItemBuilder builder) {
|
||||
if (isOminous(session, patterns)) {
|
||||
// Remove the current patterns and set the ominous banner type
|
||||
builder.putInt("Type", 1);
|
||||
} else {
|
||||
List<NbtMap> patternList = new ArrayList<>(patterns.size());
|
||||
for (BannerPatternLayer patternLayer : patterns) {
|
||||
patternLayer.getPattern().ifId(holder -> {
|
||||
BannerPattern bannerPattern = session.getRegistryCache().bannerPatterns().get(holder.id());
|
||||
if (bannerPattern != null) {
|
||||
NbtMap tag = NbtMap.builder()
|
||||
.putString("Pattern", bannerPattern.getBedrockIdentifier())
|
||||
.putInt("Color", 15 - patternLayer.getColorId())
|
||||
.build();
|
||||
patternList.add(tag);
|
||||
}
|
||||
});
|
||||
}
|
||||
builder.putList("Patterns", NbtType.COMPOUND, patternList);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the Java edition banner pattern nbt to Bedrock edition, null if the pattern doesn't exist
|
||||
*
|
||||
|
@ -166,25 +191,7 @@ public class BannerItem extends BlockItem {
|
|||
|
||||
List<BannerPatternLayer> patterns = components.get(DataComponentType.BANNER_PATTERNS);
|
||||
if (patterns != null) {
|
||||
if (isOminous(session, patterns)) {
|
||||
// Remove the current patterns and set the ominous banner type
|
||||
builder.putInt("Type", 1);
|
||||
} else {
|
||||
List<NbtMap> patternList = new ArrayList<>(patterns.size());
|
||||
for (BannerPatternLayer patternLayer : patterns) {
|
||||
patternLayer.getPattern().ifId(holder -> {
|
||||
BannerPattern bannerPattern = session.getRegistryCache().bannerPatterns().get(holder.id());
|
||||
if (bannerPattern != null) {
|
||||
NbtMap tag = NbtMap.builder()
|
||||
.putString("Pattern", bannerPattern.getBedrockIdentifier())
|
||||
.putInt("Color", 15 - patternLayer.getColorId())
|
||||
.build();
|
||||
patternList.add(tag);
|
||||
}
|
||||
});
|
||||
}
|
||||
builder.putList("Patterns", NbtType.COMPOUND, patternList);
|
||||
}
|
||||
convertBannerPattern(session, patterns, builder);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
import org.geysermc.geyser.item.components.ToolTier;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
||||
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 java.util.List;
|
||||
|
||||
public class ShieldItem extends Item {
|
||||
public ShieldItem(String javaIdentifier, Builder builder) {
|
||||
super(javaIdentifier, builder);
|
||||
|
@ -40,22 +44,15 @@ public class ShieldItem extends Item {
|
|||
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
||||
super.translateComponentsToBedrock(session, components, builder);
|
||||
|
||||
// TODO figure out patterns first.
|
||||
// if (tag.remove("BlockEntityTag") instanceof CompoundTag blockEntityTag) {
|
||||
// if (blockEntityTag.get("Patterns") instanceof ListTag patterns) {
|
||||
// for (Tag pattern : patterns) {
|
||||
// if (((CompoundTag) pattern).get("Color") instanceof IntTag color) {
|
||||
// color.setValue(15 - color.getValue());
|
||||
// }
|
||||
// }
|
||||
// // Bedrock looks for patterns at the root
|
||||
// tag.put(patterns);
|
||||
// }
|
||||
// if (blockEntityTag.get("Base") instanceof IntTag base) {
|
||||
// base.setValue(15 - base.getValue());
|
||||
// tag.put(base);
|
||||
// }
|
||||
// }
|
||||
List<BannerPatternLayer> patterns = components.get(DataComponentType.BANNER_PATTERNS);
|
||||
if (patterns != null) {
|
||||
BannerItem.convertBannerPattern(session, patterns, builder);
|
||||
}
|
||||
// Shield pattern backing color
|
||||
Integer baseColor = components.get(DataComponentType.BASE_COLOR);
|
||||
if (baseColor != null) {
|
||||
builder.putInt("Base", 15 - baseColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue