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.component.helper.ExplosionData; 025import net.tnemc.item.platform.ItemPlatform; 026import org.json.simple.JSONObject; 027 028import java.util.List; 029import java.util.Objects; 030 031/** 032 * FireworkExplosionComponent 033 * 034 * @author creatorfromhell 035 * @since 0.2.0.0 036 */ 037public abstract class FireworkExplosionComponent<I extends AbstractItemStack<T>, T> implements SerialComponent<I, T> { 038 039 protected ExplosionData explosion; 040 041 public FireworkExplosionComponent() { 042 043 } 044 045 public FireworkExplosionComponent(final ExplosionData explosion) { 046 047 this.explosion = explosion; 048 } 049 050 public FireworkExplosionComponent(final String shape, final boolean hasTrail, 051 final boolean hasTwinkle, final List<Integer> colors, 052 final List<Integer> fadeColors) { 053 054 this.explosion = new ExplosionData(shape, hasTrail, hasTwinkle, colors, fadeColors); 055 } 056 057 @Override 058 public String identifier() { 059 return "firework_explosion"; 060 } 061 062 @Override 063 public JSONObject toJSON() { 064 final JSONObject json = new JSONObject(); 065 json.put("explosion", explosion.toJSON()); 066 return json; 067 } 068 069 @Override 070 public void readJSON(final JSONHelper json, final ItemPlatform<I, T, ?> platform) { 071 if(json.has("explosion")) { 072 explosion.readJSON(json.getHelper("explosion")); 073 } 074 } 075 076 @Override 077 public boolean similar(final SerialComponent<?, ?> component) { 078 if(!(component instanceof final FireworkExplosionComponent<?, ?> other)) return false; 079 080 return Objects.equals(this.explosion, other.explosion); 081 } 082 083 @Override 084 public int hashCode() { 085 return Objects.hash(explosion); 086 } 087 088 public ExplosionData explosion() { 089 090 return explosion; 091 } 092 093 public void explosion(final ExplosionData explosion) { 094 095 this.explosion = explosion; 096 } 097}