SolidBucketItem .java

net.minecraft.world.item.SolidBucketItem (class, 56 lines): members: placeSound, emptyContents, getPlaceSound, useOn. imports: UseOnContext, GameEvent.

net.minecraft.world.itemclass56 linescommonextends BlockItem1.9 KB

Implements

API Surface (3)

InteractionResult useOn(final UseOnContext context)
SoundEvent getPlaceSound(final BlockState blockState)
boolean emptyContents(final @Nullable LivingEntity user, final Level level, final BlockPos pos, final @Nullable BlockHitResult hitResult)

Fields & Constants (1)

placeSound

Full Source

SolidBucketItem.java56 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.item;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.sounds.SoundEvent;
5
import net.minecraft.sounds.SoundSource;
6
import net.minecraft.world.InteractionResult;
7
import net.minecraft.world.entity.LivingEntity;
8
import net.minecraft.world.entity.player.Player;
9
import net.minecraft.world.item.context.UseOnContext;
10
import net.minecraft.world.level.Level;
11
import net.minecraft.world.level.block.Block;
12
import net.minecraft.world.level.block.state.BlockState;
13
import net.minecraft.world.level.gameevent.GameEvent;
14
import net.minecraft.world.phys.BlockHitResult;
15
import org.jspecify.annotations.Nullable;
16
17
public class SolidBucketItem extends BlockItem implements DispensibleContainerItem {
18
	private final SoundEvent placeSound;
19
20
	public SolidBucketItem(final Block content, final SoundEvent placeSound, final Item.Properties properties) {
21
		super(content, properties);
22
		this.placeSound = placeSound;
23
	}
24
25
	@Override
26
	public InteractionResult useOn(final UseOnContext context) {
27
		InteractionResult placeResult = super.useOn(context);
28
		Player player = context.getPlayer();
29
		if (placeResult.consumesAction() && player != null) {
30
			player.setItemInHand(context.getHand(), BucketItem.getEmptySuccessItem(context.getItemInHand(), player));
31
		}
32
33
		return placeResult;
34
	}
35
36
	@Override
37
	protected SoundEvent getPlaceSound(final BlockState blockState) {
38
		return this.placeSound;
39
	}
40
41
	@Override
42
	public boolean emptyContents(final @Nullable LivingEntity user, final Level level, final BlockPos pos, final @Nullable BlockHitResult hitResult) {
43
		if (level.isInWorldBounds(pos) && level.isEmptyBlock(pos)) {
44
			if (!level.isClientSide()) {
45
				level.setBlockAndUpdate(pos, this.getBlock().defaultBlockState());
46
			}
47
48
			level.gameEvent(user, GameEvent.FLUID_PLACE, pos);
49
			level.playSound(user, pos, this.placeSound, SoundSource.BLOCKS, 1.0F, 1.0F);
50
			return true;
51
		} else {
52
			return false;
53
		}
54
	}
55
}
56

Decompiled Minecraft 26.3 source of SolidBucketItem (net/minecraft/world/item/SolidBucketItem.java) with Mojang official mappings, stored verbatim on the site.