Search in sources :

Example 1 with PatternListValue

use of org.spongepowered.api.data.value.mutable.PatternListValue in project SpongeCommon by SpongePowered.

the class ShieldBannerDataProcessor method set.

@Override
public boolean set(ItemStack itemStack, Map<Key<?>, Object> keyValues) {
    if (itemStack.getTagCompound() == null) {
        itemStack.setTagCompound(new NBTTagCompound());
    }
    final NBTTagCompound tagCompound = ItemStackUtil.getTagCompound(itemStack);
    final NBTTagCompound blockEntity = new NBTTagCompound();
    final DyeColor baseColor = (DyeColor) keyValues.get(Keys.BANNER_BASE_COLOR);
    final PatternListValue patternLayers = (PatternListValue) keyValues.get(Keys.BANNER_PATTERNS);
    if (!patternLayers.isEmpty()) {
        final NBTTagList patterns = new NBTTagList();
        for (PatternLayer layer : patternLayers) {
            NBTTagCompound compound = new NBTTagCompound();
            compound.setString(NbtDataUtil.BANNER_PATTERN_ID, ((BannerPattern) (Object) layer.getShape()).getHashname());
            compound.setInteger(NbtDataUtil.BANNER_PATTERN_COLOR, ((EnumDyeColor) (Object) layer.getColor()).getDyeDamage());
            patterns.appendTag(compound);
        }
        blockEntity.setTag(NbtDataUtil.BANNER_PATTERNS, patterns);
    }
    blockEntity.setInteger(NbtDataUtil.BANNER_BASE, ((EnumDyeColor) (Object) baseColor).getDyeDamage());
    tagCompound.setTag(NbtDataUtil.BLOCK_ENTITY_TAG, blockEntity);
    return true;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) PatternLayer(org.spongepowered.api.data.meta.PatternLayer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PatternListValue(org.spongepowered.api.data.value.mutable.PatternListValue) DyeColor(org.spongepowered.api.data.type.DyeColor) EnumDyeColor(net.minecraft.item.EnumDyeColor)

Aggregations

EnumDyeColor (net.minecraft.item.EnumDyeColor)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 PatternLayer (org.spongepowered.api.data.meta.PatternLayer)1 DyeColor (org.spongepowered.api.data.type.DyeColor)1 PatternListValue (org.spongepowered.api.data.value.mutable.PatternListValue)1