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 * RepairCostComponent - The number of experience levels to add to the base level cost when repairing, 031 * combining, or renaming this item with an anvil. Must be a non-negative integer, defaults to 0. 032 * 033 * @author creatorfromhell 034 * @see <a href="https://minecraft.wiki/w/Data_component_format#repair_cost">Reference</a> 035 * <p> 036 * @since 0.2.0.0 037 */ 038public abstract class RepairCostComponent<I extends AbstractItemStack<T>, T> implements SerialComponent<I, T> { 039 040 protected int repairCost = 0; 041 042 public RepairCostComponent() { 043 044 } 045 046 public RepairCostComponent(final int repairCost) { 047 048 this.repairCost = repairCost; 049 } 050 051 @Override 052 public String identifier() { 053 return "repair_cost"; 054 } 055 056 @Override 057 public JSONObject toJSON() { 058 final JSONObject json = new JSONObject(); 059 json.put("repair_cost", repairCost); 060 return json; 061 } 062 063 @Override 064 public void readJSON(final JSONHelper json, final ItemPlatform<I, T, ?> platform) { 065 repairCost = json.getInteger("repair_cost"); 066 } 067 068 @Override 069 public boolean similar(final SerialComponent<?, ?> component) { 070 if(!(component instanceof final RepairCostComponent<?, ?> other)) return false; 071 return this.repairCost == other.repairCost; 072 } 073 074 @Override 075 public int hashCode() { 076 return Objects.hash(repairCost); 077 } 078 079 public int repairCost() { 080 081 return repairCost; 082 } 083 084 public void repairCost(final int repairCost) { 085 086 this.repairCost = repairCost; 087 } 088}