001/*
002 * Trident - A Multithreaded Server Alternative
003 * Copyright 2014 The TridentSDK Team
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *    http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package net.tridentsdk.server.data.item;
018
019import java.util.Arrays;
020import java.util.List;
021
022import com.google.common.collect.Lists;
023
024import net.tridentsdk.base.Color;
025import net.tridentsdk.meta.item.ExplosionMeta;
026import net.tridentsdk.meta.nbt.NBTField;
027import net.tridentsdk.meta.nbt.NBTSerializable;
028import net.tridentsdk.meta.nbt.TagType;
029
030public class ExplosionMetaImpl implements ExplosionMeta, NBTSerializable {
031    @NBTField(name = "Colors", type = TagType.INT_ARRAY)
032    private int[] mainColorsArr;
033
034    @NBTField(name = "FadeColors", type = TagType.INT_ARRAY)
035    private int[] fadeColorsArr;
036
037    @NBTField(name = "Flicker", type = TagType.BYTE)
038    private boolean flicker;
039
040    @NBTField(name = "Trail", type = TagType.BYTE)
041    private boolean trail;
042
043    @NBTField(name = "Type", type = TagType.BYTE)
044    private int type;
045
046    private ExplosionType explosionType;
047    private List<Color> mainColors;
048    private List<Color> fadeColors;
049
050    @Override
051    public void process() {
052        if (type < 0 || type >= ExplosionMeta.ExplosionType.values().length) {
053            explosionType = ExplosionMeta.ExplosionType.UNKNOWN;
054        } else {
055            explosionType = ExplosionMeta.ExplosionType.values()[type];
056        }
057
058        mainColors = Lists.newArrayListWithCapacity(mainColorsArr.length);
059        fadeColors = Lists.newArrayListWithCapacity(fadeColorsArr.length);
060
061        Arrays.stream(mainColorsArr).mapToObj((i) -> Color.fromRGB(i)).forEach(c -> mainColors.add(c));
062        Arrays.stream(fadeColorsArr).mapToObj((i) -> Color.fromRGB(i)).forEach(c -> fadeColors.add(c));
063    }
064
065    @Override
066    public List<Color> colors() {
067        return mainColors;
068    }
069
070    @Override
071    public List<Color> fadeColors() {
072        return fadeColors;
073    }
074
075    @Override
076    public ExplosionType type() {
077        return explosionType;
078    }
079
080    @Override
081    public boolean isFlicker() {
082        return flicker;
083    }
084
085    @Override
086    public boolean isTrail() {
087        return trail;
088    }
089}