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 * BucketEntityDataComponent - NBT applied to an entity when placed from this bucket. Only tags 031 * below are applied. 032 * 033 * @author creatorfromhell 034 * @see <a href="https://minecraft.wiki/w/Data_component_format#bucket_entity_data">Reference</a> 035 * <p> 036 * @since 0.2.0.0 037 */ 038public abstract class BucketEntityDataComponent<I extends AbstractItemStack<T>, T> implements SerialComponent<I, T> { 039 040 protected boolean noAI; 041 protected boolean silent; 042 protected boolean noGravity; 043 protected boolean glowing; 044 protected boolean invulnerable; 045 protected float health = 0.0f; // Default to 0 046 protected int age = 0; // Default to 0 for axolotls and tadpoles. 047 protected int variant = 0; // Default to 0 for axolotls. 048 protected long huntingCooldown = 0L; // Default to 0 for axolotls. 049 protected int bucketVariantTag = 0; // Default to 0 - for tropical fish 050 protected String type = ""; // for salmon 051 052 public BucketEntityDataComponent() { 053 054 } 055 056 public BucketEntityDataComponent(final boolean noAI, final boolean silent, final boolean noGravity, 057 final boolean glowing, final boolean invulnerable) { 058 059 this.noAI = noAI; 060 this.silent = silent; 061 this.noGravity = noGravity; 062 this.glowing = glowing; 063 this.invulnerable = invulnerable; 064 } 065 066 public BucketEntityDataComponent(final boolean noAI, final boolean silent, final boolean noGravity, 067 final boolean glowing, final boolean invulnerable, final float health, 068 final int age, final int variant, final long huntingCooldown, 069 final int bucketVariantTag, final String type) { 070 071 this.noAI = noAI; 072 this.silent = silent; 073 this.noGravity = noGravity; 074 this.glowing = glowing; 075 this.invulnerable = invulnerable; 076 this.health = health; 077 this.age = age; 078 this.variant = variant; 079 this.huntingCooldown = huntingCooldown; 080 this.bucketVariantTag = bucketVariantTag; 081 this.type = type; 082 } 083 084 @Override 085 public String identifier() { 086 return "bucket_entity_data"; 087 } 088 089 @Override 090 public JSONObject toJSON() { 091 final JSONObject json = new JSONObject(); 092 json.put("NoAI", noAI); 093 json.put("Silent", silent); 094 json.put("NoGravity", noGravity); 095 json.put("Glowing", glowing); 096 json.put("Invulnerable", invulnerable); 097 json.put("Health", health); 098 json.put("Age", age); 099 json.put("Variant", variant); 100 json.put("HuntingCooldown", huntingCooldown); 101 json.put("BucketVariantTag", bucketVariantTag); 102 json.put("type", type); 103 return json; 104 } 105 106 @Override 107 public void readJSON(final JSONHelper json, final ItemPlatform<I, T, ?> platform) { 108 noAI = json.getBoolean("NoAI"); 109 silent = json.getBoolean("Silent"); 110 noGravity = json.getBoolean("NoGravity"); 111 glowing = json.getBoolean("Glowing"); 112 invulnerable = json.getBoolean("Invulnerable"); 113 health = json.getFloat("Health"); 114 age = json.getInteger("Age"); 115 variant = json.getInteger("Variant"); 116 huntingCooldown = json.getLong("HuntingCooldown"); 117 bucketVariantTag = json.getInteger("BucketVariantTag"); 118 type = json.getString("type"); 119 } 120 121 @Override 122 public boolean similar(final SerialComponent<?, ?> component) { 123 if(!(component instanceof final BucketEntityDataComponent<?, ?> other)) return false; 124 return this.noAI == other.noAI && 125 this.silent == other.silent && 126 this.noGravity == other.noGravity && 127 this.glowing == other.glowing && 128 this.invulnerable == other.invulnerable && 129 Float.compare(this.health, other.health) == 0 && 130 this.age == other.age && 131 this.variant == other.variant && 132 this.huntingCooldown == other.huntingCooldown && 133 this.bucketVariantTag == other.bucketVariantTag && 134 Objects.equals(this.type, other.type); 135 } 136 137 @Override 138 public int hashCode() { 139 return Objects.hash(noAI, silent, noGravity, glowing, invulnerable, health, age, variant, huntingCooldown, bucketVariantTag, type); 140 } 141 142 public boolean noAI() { 143 144 return noAI; 145 } 146 147 public void noAI(final boolean noAI) { 148 149 this.noAI = noAI; 150 } 151 152 public boolean silent() { 153 154 return silent; 155 } 156 157 public void silent(final boolean silent) { 158 159 this.silent = silent; 160 } 161 162 public boolean noGravity() { 163 164 return noGravity; 165 } 166 167 public void noGravity(final boolean noGravity) { 168 169 this.noGravity = noGravity; 170 } 171 172 public boolean glowing() { 173 174 return glowing; 175 } 176 177 public void glowing(final boolean glowing) { 178 179 this.glowing = glowing; 180 } 181 182 public boolean invulnerable() { 183 184 return invulnerable; 185 } 186 187 public void invulnerable(final boolean invulnerable) { 188 189 this.invulnerable = invulnerable; 190 } 191 192 public float health() { 193 194 return health; 195 } 196 197 public void health(final float health) { 198 199 this.health = health; 200 } 201 202 public int age() { 203 204 return age; 205 } 206 207 public void age(final int age) { 208 209 this.age = age; 210 } 211 212 public int variant() { 213 214 return variant; 215 } 216 217 public void variant(final int variant) { 218 219 this.variant = variant; 220 } 221 222 public long huntingCooldown() { 223 224 return huntingCooldown; 225 } 226 227 public void huntingCooldown(final long huntingCooldown) { 228 229 this.huntingCooldown = huntingCooldown; 230 } 231 232 public int bucketVariantTag() { 233 234 return bucketVariantTag; 235 } 236 237 public void bucketVariantTag(final int bucketVariantTag) { 238 239 this.bucketVariantTag = bucketVariantTag; 240 } 241 242 public String type() { 243 244 return type; 245 } 246 247 public void type(final String type) { 248 249 this.type = type; 250 } 251}