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);
|
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
|
* 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);
|
List<BannerPatternLayer> patterns = components.get(DataComponentType.BANNER_PATTERNS);
|
||||||
if (patterns != null) {
|
if (patterns != null) {
|
||||||
if (isOminous(session, patterns)) {
|
convertBannerPattern(session, patterns, builder);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.geysermc.geyser.item.components.ToolTier;
|
import org.geysermc.geyser.item.components.ToolTier;
|
||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
|
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 org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ShieldItem extends Item {
|
public class ShieldItem extends Item {
|
||||||
public ShieldItem(String javaIdentifier, Builder builder) {
|
public ShieldItem(String javaIdentifier, Builder builder) {
|
||||||
super(javaIdentifier, 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) {
|
public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNull DataComponents components, @NonNull BedrockItemBuilder builder) {
|
||||||
super.translateComponentsToBedrock(session, components, builder);
|
super.translateComponentsToBedrock(session, components, builder);
|
||||||
|
|
||||||
// TODO figure out patterns first.
|
List<BannerPatternLayer> patterns = components.get(DataComponentType.BANNER_PATTERNS);
|
||||||
// if (tag.remove("BlockEntityTag") instanceof CompoundTag blockEntityTag) {
|
if (patterns != null) {
|
||||||
// if (blockEntityTag.get("Patterns") instanceof ListTag patterns) {
|
BannerItem.convertBannerPattern(session, patterns, builder);
|
||||||
// for (Tag pattern : patterns) {
|
}
|
||||||
// if (((CompoundTag) pattern).get("Color") instanceof IntTag color) {
|
// Shield pattern backing color
|
||||||
// color.setValue(15 - color.getValue());
|
Integer baseColor = components.get(DataComponentType.BASE_COLOR);
|
||||||
// }
|
if (baseColor != null) {
|
||||||
// }
|
builder.putInt("Base", 15 - baseColor);
|
||||||
// // 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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue