use of net.minecraft.world.item.ShieldItem in project SpongeCommon by SpongePowered.
the class ShieldItemStackData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(ItemStack.class).create(Keys.DYE_COLOR).get(h -> {
final CompoundTag tag = h.getTagElement(Constants.Item.BLOCK_ENTITY_TAG);
if (tag == null || tag.contains(Constants.TileEntity.Banner.BANNER_PATTERNS, Constants.NBT.TAG_LIST)) {
return DyeColors.WHITE.get();
}
final int id = tag.getInt(Constants.TileEntity.Banner.BANNER_BASE);
return (DyeColor) (Object) net.minecraft.world.item.DyeColor.byId(id);
}).set((h, v) -> {
final CompoundTag tag = h.getOrCreateTagElement(Constants.Item.BLOCK_ENTITY_TAG);
tag.putInt(Constants.TileEntity.Banner.BANNER_BASE, ((net.minecraft.world.item.DyeColor) (Object) v).getId());
}).supports(h -> h.getItem() instanceof ShieldItem).create(Keys.BANNER_PATTERN_LAYERS).get(h -> {
final CompoundTag tag = h.getTagElement(Constants.Item.BLOCK_ENTITY_TAG);
if (tag == null || !tag.contains(Constants.TileEntity.Banner.BANNER_PATTERNS, Constants.NBT.TAG_LIST)) {
return new ArrayList<>();
}
final ListTag layersList = tag.getList(Constants.TileEntity.Banner.BANNER_PATTERNS, Constants.NBT.TAG_COMPOUND);
return layersList.stream().map(layer -> ShieldItemStackData.layerFromNbt((CompoundTag) layer)).collect(Collectors.toList());
}).set((h, v) -> {
final ListTag layersTag = v.stream().filter(layer -> layer.shape() != BannerPatternShapes.BASE.get()).map(ShieldItemStackData::layerToNbt).collect(NBTCollectors.toTagList());
final CompoundTag blockEntity = h.getOrCreateTagElement(Constants.Item.BLOCK_ENTITY_TAG);
blockEntity.put(Constants.TileEntity.Banner.BANNER_PATTERNS, layersTag);
if (h.getItem() instanceof ShieldItem) {
// TODO reject BannerPatternShapes.BASE for BannerItem?
v.stream().filter(layer -> layer.shape() == BannerPatternShapes.BASE.get()).forEach(layer -> {
blockEntity.putInt(Constants.TileEntity.Banner.BANNER_BASE, ((net.minecraft.world.item.DyeColor) (Object) layer.color()).getId());
});
}
}).supports(h -> h.getItem() instanceof ShieldItem || h.getItem() instanceof BannerItem);
}
Aggregations