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 org.json.simple.JSONObject; 023 024import java.util.Objects; 025 026/** 027 * TeleportRandomlyReviveEffect 028 * 029 * @author creatorfromhell 030 * @since 0.2.0.0 031 */ 032public class TeleportRandomlyComponentEffect extends ComponentEffect { 033 034 private float diameter = 16.0f; // Default to 16.0 035 036 @Override 037 public String getType() { 038 return "teleport_randomly"; 039 } 040 041 @Override 042 public JSONObject toJSON() { 043 final JSONObject json = new JSONObject(); 044 json.put("type", getType()); 045 json.put("probability", probability); 046 json.put("diameter", diameter); 047 048 return json; 049 } 050 051 @Override 052 public void readJSON(final JSONHelper json) { 053 probability = json.getFloat("probability"); 054 diameter = json.getFloat("diameter"); 055 } 056 057 public float getDiameter() { 058 return diameter; 059 } 060 061 public void setDiameter(final float diameter) { 062 this.diameter = diameter; 063 } 064 065 @Override 066 public boolean equals(final Object obj) { 067 if(!(obj instanceof final TeleportRandomlyComponentEffect other)) return false; 068 069 return super.equals(obj) && Float.compare(this.diameter, other.diameter) == 0; 070 } 071 072 @Override 073 public int hashCode() { 074 return Objects.hash(super.hashCode(), diameter); 075 } 076 077 @Override 078 public TeleportRandomlyComponentEffect clone() { 079 final TeleportRandomlyComponentEffect copy = new TeleportRandomlyComponentEffect(); 080 copy.probability(this.probability); 081 copy.setDiameter(this.getDiameter()); 082 return copy; 083 } 084}