001package net.tnemc.item.component.impl;
002/*
003 * The New Item Library
004 * Copyright (C) 2022 - 2025 Daniel "creatorfromhell" Vidmar
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020
021import net.tnemc.item.AbstractItemStack;
022import net.tnemc.item.JSONHelper;
023import net.tnemc.item.component.SerialComponent;
024import net.tnemc.item.platform.ItemPlatform;
025import org.json.simple.JSONArray;
026import org.json.simple.JSONObject;
027
028import java.util.ArrayList;
029import java.util.Arrays;
030import java.util.List;
031import java.util.Objects;
032
033/**
034 * PotDecorationsComponent
035 *
036 * @author creatorfromhell
037 * @see <a href="https://minecraft.wiki/w/Data_component_format#pot_decorations">Reference</a>
038 * <p>
039 * @since 0.2.0.0
040 */
041public abstract class PotDecorationsComponent<I extends AbstractItemStack<T>, T> implements SerialComponent<I, T> {
042
043  protected final List<String> decorations = new ArrayList<>();
044
045  public PotDecorationsComponent() {
046
047  }
048
049  public PotDecorationsComponent(final List<String> decorations) {
050
051    this.decorations.addAll(decorations);
052  }
053
054  public PotDecorationsComponent(final String... decorations) {
055
056    this.decorations.addAll(Arrays.asList(decorations));
057  }
058
059  @Override
060  public String identifier() {
061    return "pot_decorations";
062  }
063
064  @Override
065  public JSONObject toJSON() {
066    final JSONObject json = new JSONObject();
067    final JSONArray array = new JSONArray();
068    array.addAll(decorations);
069    json.put("decorations", array);
070    return json;
071  }
072
073  @Override
074  public void readJSON(final JSONHelper json, final ItemPlatform<I, T, ?> platform) {
075    decorations.clear();
076    decorations.addAll(json.getStringList("decorations"));
077  }
078
079  @Override
080  public boolean similar(final SerialComponent<?, ?> component) {
081    if(!(component instanceof final PotDecorationsComponent<?, ?> other)) return false;
082    return Objects.equals(this.decorations, other.decorations);
083  }
084
085  @Override
086  public int hashCode() {
087    return Objects.hash(decorations);
088  }
089
090  public List<String> decorations() {
091
092    return decorations;
093  }
094
095  public void decorations(final List<String> decorations) {
096
097    this.decorations.clear();
098    this.decorations.addAll(decorations);
099  }
100
101  public void decorations(final String... decorations) {
102
103    this.decorations.clear();
104    this.decorations.addAll(Arrays.asList(decorations));
105  }
106}