CopperGolemStatueBlockEntity .java

net.minecraft.world.level.block.entity.CopperGolemStatueBlockEntity (class, 56 lines): members: createStatue, removeStatue, getUpdatePacket, getItem.

net.minecraft.world.level.block.entityclass56 linescommonextends BlockEntity2.4 KB

API Surface (3)

void createStatue(final CopperGolem copperGolem)
ClientboundBlockEntityDataPacket getUpdatePacket()
ItemStack getItem(final ItemStack itemStack, final CopperGolemStatueBlock.Pose pose)

Full Source

CopperGolemStatueBlockEntity.java56 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block.entity;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.component.DataComponentMap;
5
import net.minecraft.core.component.DataComponents;
6
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
7
import net.minecraft.world.entity.EntitySpawnReason;
8
import net.minecraft.world.entity.EntityTypes;
9
import net.minecraft.world.entity.animal.golem.CopperGolem;
10
import net.minecraft.world.item.ItemStack;
11
import net.minecraft.world.item.component.BlockItemStateProperties;
12
import net.minecraft.world.level.block.CopperGolemStatueBlock;
13
import net.minecraft.world.level.block.state.BlockState;
14
import net.minecraft.world.phys.Vec3;
15
import org.jspecify.annotations.Nullable;
16
17
public class CopperGolemStatueBlockEntity extends BlockEntity {
18
	public CopperGolemStatueBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
19
		super(BlockEntityTypes.COPPER_GOLEM_STATUE, worldPosition, blockState);
20
	}
21
22
	public void createStatue(final CopperGolem copperGolem) {
23
		this.setComponents(DataComponentMap.builder().addAll(this.components()).set(DataComponents.CUSTOM_NAME, copperGolem.getCustomName()).build());
24
		super.setChanged();
25
	}
26
27
	public @Nullable CopperGolem removeStatue(final BlockState state) {
28
		CopperGolem copperGolem = EntityTypes.COPPER_GOLEM.create(this.level, EntitySpawnReason.TRIGGERED);
29
		if (copperGolem != null) {
30
			copperGolem.setCustomName(this.components().get(DataComponents.CUSTOM_NAME));
31
			return this.initCopperGolem(state, copperGolem);
32
		} else {
33
			return null;
34
		}
35
	}
36
37
	private CopperGolem initCopperGolem(final BlockState state, final CopperGolem copperGolem) {
38
		BlockPos blockPos = this.getBlockPos();
39
		copperGolem.snapTo(Vec3.atCenterOf(blockPos).x, blockPos.getY(), Vec3.atCenterOf(blockPos).z, state.getValue(CopperGolemStatueBlock.FACING).toYRot(), 0.0F);
40
		copperGolem.yHeadRot = copperGolem.getYRot();
41
		copperGolem.yBodyRot = copperGolem.getYRot();
42
		copperGolem.playSpawnSound();
43
		return copperGolem;
44
	}
45
46
	public ClientboundBlockEntityDataPacket getUpdatePacket() {
47
		return ClientboundBlockEntityDataPacket.create(this);
48
	}
49
50
	public ItemStack getItem(final ItemStack itemStack, final CopperGolemStatueBlock.Pose pose) {
51
		itemStack.applyComponents(this.collectComponents());
52
		itemStack.set(DataComponents.BLOCK_STATE, BlockItemStateProperties.EMPTY.with(CopperGolemStatueBlock.POSE, pose));
53
		return itemStack;
54
	}
55
}
56

Decompiled Minecraft 26.3 source of CopperGolemStatueBlockEntity (net/minecraft/world/level/block/entity/CopperGolemStatueBlockEntity.java) with Mojang official mappings, stored verbatim on the site.