001package net.tnemc.item.component.helper.effect; 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.JSONHelper; 022import net.tnemc.item.component.helper.ItemDamage; 023import org.json.simple.JSONObject; 024 025import java.util.Objects; 026 027/** 028 * EffectInstance 029 * 030 * @author creatorfromhell 031 * @since 0.2.0.0 032 */ 033public class EffectInstance { 034 035 protected String id; 036 protected int amplifier = 0; 037 protected int duration = 1; 038 protected boolean ambient = false; 039 protected boolean showParticles = true; 040 protected boolean showIcon = true; 041 042 public EffectInstance() { 043 044 } 045 046 public EffectInstance(final String id) { 047 048 this.id = id; 049 } 050 051 public EffectInstance(final String id, final int amplifier, final int duration, 052 final boolean showParticles, final boolean ambient, final boolean showIcon) { 053 054 this.id = id; 055 this.amplifier = amplifier; 056 this.duration = duration; 057 this.showParticles = showParticles; 058 this.ambient = ambient; 059 this.showIcon = showIcon; 060 } 061 062 public JSONObject toJSON() { 063 final JSONObject json = new JSONObject(); 064 json.put("id", id); 065 json.put("amplifier", amplifier); 066 json.put("duration", duration); 067 json.put("ambient", ambient); 068 json.put("show_particles", showParticles); 069 json.put("show_icon", showIcon); 070 return json; 071 } 072 073 public void readJSON(final JSONHelper json) { 074 id = json.getString("id"); 075 amplifier = json.getInteger("amplifier"); 076 duration = json.getInteger("duration"); 077 ambient = json.getBoolean("ambient"); 078 showParticles = json.getBoolean("show_particles"); 079 showIcon = json.getBoolean("show_icon"); 080 } 081 082 @Override 083 public boolean equals(final Object obj) { 084 if(!(obj instanceof final EffectInstance other)) return false; 085 086 return Objects.equals(this.id, other.id) && 087 this.amplifier == other.amplifier && 088 this.duration == other.duration && 089 this.ambient == other.ambient && 090 this.showParticles == other.showParticles && 091 this.showIcon == other.showIcon; 092 } 093 094 @Override 095 public int hashCode() { 096 return Objects.hash(id, amplifier, duration, ambient, showParticles, showIcon); 097 } 098 099 public String id() { 100 101 return id; 102 } 103 104 public void id(final String id) { 105 106 this.id = id; 107 } 108 109 public int amplifier() { 110 111 return amplifier; 112 } 113 114 public void amplifier(final int amplifier) { 115 116 this.amplifier = amplifier; 117 } 118 119 public int duration() { 120 121 return duration; 122 } 123 124 public void duration(final int duration) { 125 126 this.duration = duration; 127 } 128 129 public boolean ambient() { 130 131 return ambient; 132 } 133 134 public void ambient(final boolean ambient) { 135 136 this.ambient = ambient; 137 } 138 139 public boolean showParticles() { 140 141 return showParticles; 142 } 143 144 public void showParticles(final boolean showParticles) { 145 146 this.showParticles = showParticles; 147 } 148 149 public boolean showIcon() { 150 151 return showIcon; 152 } 153 154 public void showIcon(final boolean showIcon) { 155 156 this.showIcon = showIcon; 157 } 158 159 @Override 160 public EffectInstance clone() throws CloneNotSupportedException { 161 return new EffectInstance( 162 this.id, 163 this.amplifier, 164 this.duration, 165 this.showParticles, 166 this.ambient, 167 this.showIcon 168 ); 169 } 170}