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.component.SerialComponent;
023
024import java.util.Map;
025import java.util.Objects;
026
027/**
028 * StoredEnchantmentsComponents - Can contain either the following fields, or key-value pairs of levels of enchantments.
029 *
030 * @author creatorfromhell
031 * @see <a href="https://minecraft.wiki/w/Data_component_format#stored_enchantments">Reference</a>
032 * <p>
033 * @since 0.2.0.0
034 */
035public abstract class StoredEnchantmentsComponent<I extends AbstractItemStack<T>, T> extends EnchantmentsComponent<I, T> {
036
037  public StoredEnchantmentsComponent() {
038
039  }
040
041  public StoredEnchantmentsComponent(final Map<String, Integer> levels) {
042
043    super(levels);
044  }
045
046  @Override
047  public String identifier() {
048    return "stored_enchantments";
049  }
050
051  @Override
052  public boolean similar(final SerialComponent<?, ?> component) {
053    if(!(component instanceof final StoredEnchantmentsComponent<?, ?> other)) return false;
054    return Objects.equals(this.levels, other.levels);
055  }
056
057  @Override
058  public int hashCode() {
059    return Objects.hash(super.hashCode(), levels);
060  }
061}