Commits

Parker Hawke authored and md_5 committed 5daeb502ac7
SPIGOT-7422, #1228: Add API to set sherds on decorated pots
No tags

src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java

Modified
1 1 package org.bukkit.craftbukkit.block;
2 2
3 +import com.google.common.base.Preconditions;
4 +import java.util.EnumMap;
3 5 import java.util.List;
6 +import java.util.Map;
4 7 import java.util.stream.Collectors;
8 +import net.minecraft.world.item.Item;
9 +import net.minecraft.world.item.Items;
5 10 import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity;
6 11 import org.bukkit.Material;
12 +import org.bukkit.Tag;
7 13 import org.bukkit.World;
8 14 import org.bukkit.block.DecoratedPot;
9 15 import org.bukkit.craftbukkit.util.CraftMagicNumbers;
10 16
11 17 public class CraftDecoratedPot extends CraftBlockEntityState<DecoratedPotBlockEntity> implements DecoratedPot {
12 18
13 19 public CraftDecoratedPot(World world, DecoratedPotBlockEntity tileEntity) {
14 20 super(world, tileEntity);
15 21 }
16 22
23 + @Override
24 + public void setSherd(Side face, Material sherd) {
25 + Preconditions.checkArgument(face != null, "face must not be null");
26 + Preconditions.checkArgument(sherd == null || sherd == Material.BRICK || Tag.ITEMS_DECORATED_POT_SHERDS.isTagged(sherd), "sherd is not a valid sherd material: %s", sherd);
27 +
28 + Item sherdItem = (sherd != null) ? CraftMagicNumbers.getItem(sherd) : Items.BRICK;
29 + DecoratedPotBlockEntity.a decorations = getSnapshot().getDecorations(); // PAIL rename Decorations
30 +
31 + switch (face) {
32 + case BACK -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(sherdItem, decorations.left(), decorations.right(), decorations.front());
33 + case LEFT -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(decorations.back(), sherdItem, decorations.right(), decorations.front());
34 + case RIGHT -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(decorations.back(), decorations.left(), sherdItem, decorations.front());
35 + case FRONT -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(decorations.back(), decorations.left(), decorations.right(), sherdItem);
36 + default -> throw new IllegalArgumentException("Unexpected value: " + face);
37 + }
38 + }
39 +
40 + @Override
41 + public Material getSherd(Side face) {
42 + Preconditions.checkArgument(face != null, "face must not be null");
43 +
44 + DecoratedPotBlockEntity.a decorations = getSnapshot().getDecorations(); // PAIL rename Decorations
45 + Item sherdItem = switch (face) {
46 + case BACK -> decorations.back();
47 + case LEFT -> decorations.left();
48 + case RIGHT -> decorations.right();
49 + case FRONT -> decorations.front();
50 + default -> throw new IllegalArgumentException("Unexpected value: " + face);
51 + };
52 +
53 + return CraftMagicNumbers.getMaterial(sherdItem);
54 + }
55 +
56 + @Override
57 + public Map<Side, Material> getSherds() {
58 + DecoratedPotBlockEntity.a decorations = getSnapshot().getDecorations(); // PAIL rename Decorations
59 +
60 + Map<Side, Material> sherds = new EnumMap<>(Side.class);
61 + sherds.put(Side.BACK, CraftMagicNumbers.getMaterial(decorations.back()));
62 + sherds.put(Side.LEFT, CraftMagicNumbers.getMaterial(decorations.left()));
63 + sherds.put(Side.RIGHT, CraftMagicNumbers.getMaterial(decorations.right()));
64 + sherds.put(Side.FRONT, CraftMagicNumbers.getMaterial(decorations.front()));
65 + return sherds;
66 + }
67 +
17 68 @Override
18 69 public List<Material> getShards() {
19 70 return getSnapshot().getDecorations().sorted().map(CraftMagicNumbers::getMaterial).collect(Collectors.toUnmodifiableList());
20 71 }
21 72 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut