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 * ReviveEffect
028 *
029 * @author creatorfromhell
030 * @since 0.2.0.0
031 */
032public abstract class ComponentEffect {
033
034  protected float probability = 1.0f; // Default to 100% chance
035
036  public abstract String getType();
037
038  public abstract JSONObject toJSON();
039
040  public abstract void readJSON(JSONHelper json);
041
042  public float probability() {
043
044    return probability;
045  }
046
047  public void probability(final float probability) {
048
049    this.probability = probability;
050  }
051
052  @Override
053  public boolean equals(final Object obj) {
054    if(!(obj instanceof final ComponentEffect other)) return false;
055
056    return Float.compare(this.probability, other.probability) == 0;
057  }
058
059  @Override
060  public int hashCode() {
061    return Objects.hash(probability);
062  }
063}