98 lines
3.2 KiB
Java
98 lines
3.2 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package net.minecraft.world.entity.projectile;
|
|
|
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
|
import net.minecraft.network.syncher.SynchedEntityData;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.SlotAccess;
|
|
import net.minecraft.world.entity.projectile.AbstractHurtingProjectile;
|
|
import net.minecraft.world.entity.projectile.ItemSupplier;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.storage.ValueInput;
|
|
import net.minecraft.world.level.storage.ValueOutput;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public abstract class Fireball
|
|
extends AbstractHurtingProjectile
|
|
implements ItemSupplier {
|
|
private static final float MIN_CAMERA_DISTANCE_SQUARED = 12.25f;
|
|
private static final EntityDataAccessor<ItemStack> DATA_ITEM_STACK = SynchedEntityData.defineId(Fireball.class, EntityDataSerializers.ITEM_STACK);
|
|
|
|
public Fireball(EntityType<? extends Fireball> type, Level level) {
|
|
super((EntityType<? extends AbstractHurtingProjectile>)type, level);
|
|
}
|
|
|
|
public Fireball(EntityType<? extends Fireball> type, double x, double y, double z, Vec3 direction, Level level) {
|
|
super(type, x, y, z, direction, level);
|
|
}
|
|
|
|
public Fireball(EntityType<? extends Fireball> type, LivingEntity mob, Vec3 direction, Level level) {
|
|
super(type, mob, direction, level);
|
|
}
|
|
|
|
public void setItem(ItemStack source) {
|
|
if (source.isEmpty()) {
|
|
this.getEntityData().set(DATA_ITEM_STACK, this.getDefaultItem());
|
|
} else {
|
|
this.getEntityData().set(DATA_ITEM_STACK, source.copyWithCount(1));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void playEntityOnFireExtinguishedSound() {
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getItem() {
|
|
return this.getEntityData().get(DATA_ITEM_STACK);
|
|
}
|
|
|
|
@Override
|
|
protected void defineSynchedData(SynchedEntityData.Builder entityData) {
|
|
entityData.define(DATA_ITEM_STACK, this.getDefaultItem());
|
|
}
|
|
|
|
@Override
|
|
protected void addAdditionalSaveData(ValueOutput output) {
|
|
super.addAdditionalSaveData(output);
|
|
output.store("Item", ItemStack.CODEC, this.getItem());
|
|
}
|
|
|
|
@Override
|
|
protected void readAdditionalSaveData(ValueInput input) {
|
|
super.readAdditionalSaveData(input);
|
|
this.setItem(input.read("Item", ItemStack.CODEC).orElse(this.getDefaultItem()));
|
|
}
|
|
|
|
private ItemStack getDefaultItem() {
|
|
return new ItemStack(Items.FIRE_CHARGE);
|
|
}
|
|
|
|
@Override
|
|
public @Nullable SlotAccess getSlot(int slot) {
|
|
if (slot == 0) {
|
|
return SlotAccess.of(this::getItem, this::setItem);
|
|
}
|
|
return super.getSlot(slot);
|
|
}
|
|
|
|
@Override
|
|
public boolean shouldRenderAtSqrDistance(double distance) {
|
|
if (this.tickCount < 2 && distance < 12.25) {
|
|
return false;
|
|
}
|
|
return super.shouldRenderAtSqrDistance(distance);
|
|
}
|
|
}
|
|
|