/* * Decompiled with CFR 0.152. * * Could not load the following classes: * org.jspecify.annotations.Nullable */ package net.minecraft.world.item; import net.minecraft.core.BlockPos; import net.minecraft.core.component.DataComponents; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntitySpawnReason; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.animal.Bucketable; import net.minecraft.world.item.BucketItem; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.component.CustomData; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.material.Fluid; import org.jspecify.annotations.Nullable; public class MobBucketItem extends BucketItem { private final EntityType type; private final SoundEvent emptySound; public MobBucketItem(EntityType type, Fluid content, SoundEvent emptySound, Item.Properties properties) { super(content, properties); this.type = type; this.emptySound = emptySound; } @Override public void checkExtraContent(@Nullable LivingEntity user, Level level, ItemStack itemStack, BlockPos pos) { if (level instanceof ServerLevel) { this.spawn((ServerLevel)level, itemStack, pos); level.gameEvent((Entity)user, GameEvent.ENTITY_PLACE, pos); } } @Override protected void playEmptySound(@Nullable LivingEntity user, LevelAccessor level, BlockPos pos) { level.playSound(user, pos, this.emptySound, SoundSource.NEUTRAL, 1.0f, 1.0f); } private void spawn(ServerLevel level, ItemStack itemStack, BlockPos spawnPos) { Mob mob = this.type.create(level, EntityType.createDefaultStackConfig(level, itemStack, null), spawnPos, EntitySpawnReason.BUCKET, true, false); if (mob instanceof Bucketable) { Bucketable bucketable = (Bucketable)((Object)mob); CustomData entityData = itemStack.getOrDefault(DataComponents.BUCKET_ENTITY_DATA, CustomData.EMPTY); bucketable.loadFromBucketTag(entityData.copyTag()); bucketable.setFromBucket(true); } if (mob != null) { level.addFreshEntityWithPassengers(mob); mob.playAmbientSound(); } } }