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.JSONObject;
026
027import java.util.Objects;
028
029/**
030 * TrimComponent
031 *
032 * @author creatorfromhell
033 * @see <a href="https://minecraft.wiki/w/Data_component_format#trim">Reference</a>
034 * <p>
035 * @since 0.2.0.0
036 */
037public abstract class TrimComponent<I extends AbstractItemStack<T>, T> implements SerialComponent<I, T> {
038
039  protected String pattern = "";
040  protected String material = "";
041
042  public TrimComponent() {
043
044  }
045
046  public TrimComponent(final String pattern, final String material) {
047
048    this.pattern = pattern;
049    this.material = material;
050  }
051
052  @Override
053  public String identifier() {
054    return "trim";
055  }
056
057  @Override
058  public JSONObject toJSON() {
059    final JSONObject json = new JSONObject();
060    json.put("pattern", pattern);
061    json.put("material", material);
062    return json;
063  }
064
065  @Override
066  public void readJSON(final JSONHelper json, final ItemPlatform<I, T, ?> platform) {
067    pattern = json.getString("pattern");
068    material = json.getString("material");
069  }
070
071  @Override
072  public boolean similar(final SerialComponent<?, ?> component) {
073    if(!(component instanceof final TrimComponent<?, ?> other)) return false;
074    return Objects.equals(this.pattern, other.pattern) &&
075           Objects.equals(this.material, other.material);
076  }
077
078  @Override
079  public int hashCode() {
080    return Objects.hash(super.hashCode(), pattern, material);
081  }
082
083  public String pattern() {
084
085    return pattern;
086  }
087
088  public void pattern(final String pattern) {
089
090    this.pattern = pattern;
091  }
092
093  public String material() {
094
095    return material;
096  }
097
098  public void material(final String material) {
099
100    this.material = material;
101  }
102}