Search in sources :

Example 1 with PatternLayer

use of org.spongepowered.api.data.meta.PatternLayer in project SpongeCommon by SpongePowered.

the class TileEntityBannerDataProcessor method fill.

@Override
public Optional<BannerData> fill(DataContainer container, BannerData bannerData) {
    if (container.contains(Keys.BANNER_PATTERNS.getQuery()) || container.contains(Keys.BANNER_BASE_COLOR.getQuery())) {
        List<PatternLayer> layers = container.getSerializableList(Keys.BANNER_PATTERNS.getQuery(), PatternLayer.class).get();
        String colorId = container.getString(Keys.BANNER_BASE_COLOR.getQuery()).get();
        DyeColor color = Sponge.getRegistry().getType(DyeColor.class, colorId).get();
        bannerData.set(Keys.BANNER_BASE_COLOR, color);
        bannerData.set(Keys.BANNER_PATTERNS, layers);
        return Optional.of(bannerData);
    }
    return Optional.empty();
}
Also used : PatternLayer(org.spongepowered.api.data.meta.PatternLayer) DyeColor(org.spongepowered.api.data.type.DyeColor)

Example 2 with PatternLayer

use of org.spongepowered.api.data.meta.PatternLayer in project SpongeCommon by SpongePowered.

the class TileEntityBannerDataProcessor method set.

@SuppressWarnings("unchecked")
@Override
protected boolean set(TileEntityBanner entity, Map<Key<?>, Object> keyValues) {
    if (!entity.getWorld().isRemote) {
        List<PatternLayer> layers = (List<PatternLayer>) keyValues.get(Keys.BANNER_PATTERNS);
        DyeColor baseColor = (DyeColor) keyValues.get(Keys.BANNER_BASE_COLOR);
        ((IMixinBanner) entity).setLayers(layers);
        ((IMixinBanner) entity).setBaseColor(baseColor);
        return true;
    }
    return false;
}
Also used : PatternLayer(org.spongepowered.api.data.meta.PatternLayer) List(java.util.List) DyeColor(org.spongepowered.api.data.type.DyeColor) IMixinBanner(org.spongepowered.common.interfaces.block.tile.IMixinBanner)

Example 3 with PatternLayer

use of org.spongepowered.api.data.meta.PatternLayer in project SpongeCommon by SpongePowered.

the class MixinTileEntityBanner method setLayers.

@Override
public void setLayers(List<PatternLayer> layers) {
    this.patternLayers = new NonNullArrayList<>();
    this.patternLayers.addAll(layers);
    this.patterns = new NBTTagList();
    for (PatternLayer layer : this.patternLayers) {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setString(NbtDataUtil.BANNER_PATTERN_ID, layer.getShape().getName());
        compound.setInteger(NbtDataUtil.BANNER_PATTERN_COLOR, ((EnumDyeColor) (Object) layer.getColor()).getDyeDamage());
        this.patterns.appendTag(compound);
    }
    markDirtyAndUpdate();
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) PatternLayer(org.spongepowered.api.data.meta.PatternLayer) SpongePatternLayer(org.spongepowered.common.data.meta.SpongePatternLayer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 4 with PatternLayer

use of org.spongepowered.api.data.meta.PatternLayer in project SpongeCommon by SpongePowered.

the class SpongeBannerBuilder method buildContent.

@Override
protected Optional<Banner> buildContent(DataView container) throws InvalidDataException {
    return super.buildContent(container).flatMap(banner1 -> {
        if (!container.contains(DataQueries.BASE) || !container.contains(DataQueries.PATTERNS)) {
            ((TileEntity) banner1).invalidate();
            return Optional.empty();
        }
        // TODO when banner data is implemented.
        final BannerData bannerData = new SpongeBannerData();
        String dyeColorId = container.getString(DataQueries.BASE).get();
        Optional<DyeColor> colorOptional = Sponge.getRegistry().getType(DyeColor.class, dyeColorId);
        if (!colorOptional.isPresent()) {
            throw new InvalidDataException("The provided container has an invalid dye color entry!");
        }
        bannerData.set(Keys.BANNER_BASE_COLOR, colorOptional.get());
        // Now we have to get the patterns list
        final List<PatternLayer> patternsList = container.getSerializableList(DataQueries.PATTERNS, PatternLayer.class).get();
        final ListValue<PatternLayer> patternLayers = bannerData.patternsList();
        patternsList.forEach(patternLayers::add);
        bannerData.set(patternLayers);
        banner1.offer(bannerData);
        ((TileEntityBanner) banner1).validate();
        return Optional.of(banner1);
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) SpongeBannerData(org.spongepowered.common.data.manipulator.mutable.tileentity.SpongeBannerData) PatternLayer(org.spongepowered.api.data.meta.PatternLayer) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) SpongeBannerData(org.spongepowered.common.data.manipulator.mutable.tileentity.SpongeBannerData) BannerData(org.spongepowered.api.data.manipulator.mutable.tileentity.BannerData) DyeColor(org.spongepowered.api.data.type.DyeColor) TileEntityBanner(net.minecraft.tileentity.TileEntityBanner)

Example 5 with PatternLayer

use of org.spongepowered.api.data.meta.PatternLayer 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

PatternLayer (org.spongepowered.api.data.meta.PatternLayer)6 DyeColor (org.spongepowered.api.data.type.DyeColor)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 IMixinBanner (org.spongepowered.common.interfaces.block.tile.IMixinBanner)2 List (java.util.List)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityBanner (net.minecraft.tileentity.TileEntityBanner)1 BannerData (org.spongepowered.api.data.manipulator.mutable.tileentity.BannerData)1 InvalidDataException (org.spongepowered.api.data.persistence.InvalidDataException)1 PatternListValue (org.spongepowered.api.data.value.mutable.PatternListValue)1 SpongeBannerData (org.spongepowered.common.data.manipulator.mutable.tileentity.SpongeBannerData)1 SpongePatternLayer (org.spongepowered.common.data.meta.SpongePatternLayer)1