/* * Decompiled with CFR 0.152. */ 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.projectile.ItemSupplier; import net.minecraft.world.entity.projectile.ThrowableProjectile; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.storage.ValueInput; import net.minecraft.world.level.storage.ValueOutput; public abstract class ThrowableItemProjectile extends ThrowableProjectile implements ItemSupplier { private static final EntityDataAccessor DATA_ITEM_STACK = SynchedEntityData.defineId(ThrowableItemProjectile.class, EntityDataSerializers.ITEM_STACK); public ThrowableItemProjectile(EntityType type, Level level) { super((EntityType)type, level); } public ThrowableItemProjectile(EntityType type, double x, double y, double z, Level level, ItemStack itemStack) { super(type, x, y, z, level); this.setItem(itemStack); } public ThrowableItemProjectile(EntityType type, LivingEntity owner, Level level, ItemStack itemStack) { this(type, owner.getX(), owner.getEyeY() - (double)0.1f, owner.getZ(), level, itemStack); this.setOwner(owner); } public void setItem(ItemStack source) { this.getEntityData().set(DATA_ITEM_STACK, source.copyWithCount(1)); } protected abstract Item getDefaultItem(); @Override public ItemStack getItem() { return this.getEntityData().get(DATA_ITEM_STACK); } @Override protected void defineSynchedData(SynchedEntityData.Builder entityData) { entityData.define(DATA_ITEM_STACK, new ItemStack(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).orElseGet(() -> new ItemStack(this.getDefaultItem()))); } }