From 4d235919d6d649568f91b80e04672eeca64372b1 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 19 Jul 2023 07:41:31 +1000 Subject: [PATCH] SPIGOT-7422, #1228: Add API to set sherds on decorated pots By: Parker Hawke --- .../craftbukkit/block/CraftDecoratedPot.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java index 41b9d49acc..b871258709 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftDecoratedPot.java @@ -1,9 +1,15 @@ package org.bukkit.craftbukkit.block; +import com.google.common.base.Preconditions; +import java.util.EnumMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity; import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.World; import org.bukkit.block.DecoratedPot; import org.bukkit.craftbukkit.util.CraftMagicNumbers; @@ -14,6 +20,51 @@ public class CraftDecoratedPot extends CraftBlockEntityState getSnapshot().decorations = new DecoratedPotBlockEntity.a(sherdItem, decorations.left(), decorations.right(), decorations.front()); + case LEFT -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(decorations.back(), sherdItem, decorations.right(), decorations.front()); + case RIGHT -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(decorations.back(), decorations.left(), sherdItem, decorations.front()); + case FRONT -> getSnapshot().decorations = new DecoratedPotBlockEntity.a(decorations.back(), decorations.left(), decorations.right(), sherdItem); + default -> throw new IllegalArgumentException("Unexpected value: " + face); + } + } + + @Override + public Material getSherd(Side face) { + Preconditions.checkArgument(face != null, "face must not be null"); + + DecoratedPotBlockEntity.a decorations = getSnapshot().getDecorations(); // PAIL rename Decorations + Item sherdItem = switch (face) { + case BACK -> decorations.back(); + case LEFT -> decorations.left(); + case RIGHT -> decorations.right(); + case FRONT -> decorations.front(); + default -> throw new IllegalArgumentException("Unexpected value: " + face); + }; + + return CraftMagicNumbers.getMaterial(sherdItem); + } + + @Override + public Map getSherds() { + DecoratedPotBlockEntity.a decorations = getSnapshot().getDecorations(); // PAIL rename Decorations + + Map sherds = new EnumMap<>(Side.class); + sherds.put(Side.BACK, CraftMagicNumbers.getMaterial(decorations.back())); + sherds.put(Side.LEFT, CraftMagicNumbers.getMaterial(decorations.left())); + sherds.put(Side.RIGHT, CraftMagicNumbers.getMaterial(decorations.right())); + sherds.put(Side.FRONT, CraftMagicNumbers.getMaterial(decorations.front())); + return sherds; + } + @Override public List getShards() { return getSnapshot().getDecorations().sorted().map(CraftMagicNumbers::getMaterial).collect(Collectors.toUnmodifiableList());