Test fixes

Mostly around the fact that player inventories now properly support
setting and getting the BODY and SADDLE equipment slot. The slots are
exposed to the API via the extra contents array.
This commit is contained in:
Bjarne Koll
2025-06-01 19:53:44 +02:00
parent d16b93e646
commit c34fb5f8b8
11 changed files with 48 additions and 30 deletions

View File

@@ -476,7 +476,12 @@ public enum EntityEffect {
*
* @see org.bukkit.inventory.EquipmentSlot#SADDLE
*/
BREAK_EQUIPMENT_SADDLE(68, LivingEntity.class);
BREAK_EQUIPMENT_SADDLE(68, LivingEntity.class),
/**
* Ravanager roars.
*/
RAVAGER_ROARED(69, Ravager.class),
;
private final byte data;
private final Set<Class<? extends Entity>> applicableClasses;

View File

@@ -308,7 +308,7 @@ public final class GameRule<T> implements net.kyori.adventure.translation.Transl
/**
* Configures if the world uses the locator bar.
*/
public static final GameRule<Boolean> USE_LOCATOR_BAR = new GameRule<>("useLocatorBar", Boolean.class);
public static final GameRule<Boolean> LOCATOR_BAR = new GameRule<>("locatorBar", Boolean.class);
// All GameRules instantiated above this for organizational purposes
private final String name;

View File

@@ -60,6 +60,7 @@ import org.bukkit.block.data.type.DaylightDetector;
import org.bukkit.block.data.type.DecoratedPot;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.block.data.type.Door;
import org.bukkit.block.data.type.DriedGhast;
import org.bukkit.block.data.type.Dripleaf;
import org.bukkit.block.data.type.EndPortalFrame;
import org.bukkit.block.data.type.EnderChest;
@@ -960,7 +961,7 @@ public enum Material implements Keyed, Translatable, net.kyori.adventure.transla
DRAGON_EGG(-1),
DRAGON_HEAD(-1, Skull.class),
DRAGON_WALL_HEAD(-1, WallSkull.class),
DRIED_GHAST(-1, Directional.class),
DRIED_GHAST(-1, DriedGhast.class),
DRIED_KELP_BLOCK(-1),
DRIPSTONE_BLOCK(-1),
DROPPER(-1, Dispenser.class),

View File

@@ -53,6 +53,7 @@ import org.bukkit.block.data.type.DaylightDetector;
import org.bukkit.block.data.type.DecoratedPot;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.block.data.type.Door;
import org.bukkit.block.data.type.DriedGhast;
import org.bukkit.block.data.type.Dripleaf;
import org.bukkit.block.data.type.EndPortalFrame;
import org.bukkit.block.data.type.EnderChest;
@@ -898,7 +899,7 @@ public interface BlockType extends Keyed, Translatable, net.kyori.adventure.tran
BlockType.Typed<WallSkull> DRAGON_WALL_HEAD = getBlockType("dragon_wall_head");
BlockType.Typed<Directional> DRIED_GHAST = getBlockType("dried_ghast");
BlockType.Typed<DriedGhast> DRIED_GHAST = getBlockType("dried_ghast");
BlockType.Typed<BlockData> DRIED_KELP_BLOCK = getBlockType("dried_kelp_block");

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/entity/player/Inventory.java
+++ b/net/minecraft/world/entity/player/Inventory.java
@@ -56,6 +_,70 @@
@@ -56,6 +_,80 @@
public final Player player;
public final EntityEquipment equipment;
private int timesChanged;
@@ -24,9 +24,19 @@
+ }
+
+ public java.util.List<ItemStack> getArmorContents() {
+ java.util.List<ItemStack> items = new java.util.ArrayList<>(4);
+ for (EquipmentSlot equipmentSlot : EQUIPMENT_SLOTS_SORTED_BY_INDEX) {
+ if (equipmentSlot.getType() == EquipmentSlot.Type.HUMANOID_ARMOR) {
+ items.add(this.equipment.get(equipmentSlot));
+ }
+ }
+ return items;
+ }
+
+ public java.util.List<ItemStack> getExtraContent() {
+ java.util.List<ItemStack> items = new java.util.ArrayList<>();
+ for (EquipmentSlot equipmentSlot : EQUIPMENT_SLOTS_SORTED_BY_INDEX) {
+ if (equipmentSlot.isArmor()) {
+ if (equipmentSlot.getType() != EquipmentSlot.Type.HUMANOID_ARMOR) { // Non humanoid armor is considered extra
+ items.add(this.equipment.get(equipmentSlot));
+ }
+ }

View File

@@ -71,8 +71,8 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
@Override
public void setItem(int index, ItemStack item) {
// Paper start - Validate setItem index
if (index < 0 || index > 40) {
throw new ArrayIndexOutOfBoundsException("Index must be between 0 and 40");
if (index < 0 || index > 42) {
throw new ArrayIndexOutOfBoundsException("Index must be between 0 and 42");
}
// Paper end - Validate setItem index
super.setItem(index, item);
@@ -123,11 +123,8 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
switch (slot) {
case HAND -> this.setItemInMainHand(item);
case OFF_HAND, FEET, LEGS, CHEST, HEAD ->
case OFF_HAND, FEET, LEGS, CHEST, HEAD, BODY, SADDLE ->
this.getInventory().equipment.set(CraftEquipmentSlot.getNMS(slot), CraftItemStack.asNMSCopy(item));
case BODY -> throw new IllegalArgumentException("BODY is not valid for players!"); // Paper end
default ->
throw new IllegalArgumentException("Could not set slot " + slot + " - not a valid slot for PlayerInventory");
}
}
@@ -142,10 +139,7 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
return switch (slot) {
case HAND -> this.getItemInMainHand();
case OFF_HAND, FEET, LEGS, CHEST, HEAD -> CraftItemStack.asCraftMirror(this.getInventory().equipment.get(CraftEquipmentSlot.getNMS(slot)));
case BODY -> throw new IllegalArgumentException("BODY is not valid for players!");
default ->
throw new IllegalArgumentException("Could not get slot " + slot + " - not a valid slot for PlayerInventory");
case OFF_HAND, FEET, LEGS, CHEST, HEAD, BODY, SADDLE -> CraftItemStack.asCraftMirror(this.getInventory().equipment.get(CraftEquipmentSlot.getNMS(slot)));
};
}
@@ -253,12 +247,12 @@ public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.i
@Override
public ItemStack[] getExtraContents() {
return this.asCraftMirror(List.of(this.getInventory().equipment.get(net.minecraft.world.entity.EquipmentSlot.OFFHAND)));
return this.asCraftMirror(this.getInventory().getExtraContent());
}
@Override
public void setExtraContents(ItemStack[] items) {
this.setSlots(items, this.getInventory().getNonEquipmentItems().size() + this.getInventory().getArmorContents().size(), 1);
this.setSlots(items, this.getInventory().getNonEquipmentItems().size() + this.getInventory().getArmorContents().size(), 3);
}
@Override

View File

@@ -17,7 +17,7 @@ public final class ApiVersion implements Comparable<ApiVersion>, Serializable {
static {
versions = new HashMap<>();
CURRENT = getOrCreateVersion("1.21.5");
CURRENT = getOrCreateVersion("1.21.6");
FLATTENING = getOrCreateVersion("1.13");
FIELD_NAME_PARITY = getOrCreateVersion("1.20.5");
ABSTRACT_COW = getOrCreateVersion("1.21.5");

View File

@@ -520,7 +520,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.EMPTY);
}
return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.CODEC.parse(
MinecraftServer.getServer().registryAccess().createSerializationContext(NbtOps.INSTANCE), compound
CraftRegistry.getMinecraftRegistry().createSerializationContext(NbtOps.INSTANCE), compound
).getOrThrow());
}

View File

@@ -31,8 +31,8 @@ public final class CommandPermissions {
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "selector", "Allows the use of selectors", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "trigger", "Allows the use of the trigger command", PermissionDefault.TRUE, commands);
// Paper start
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "attribute", "Allows the user to query, add, remove or set an entity attribute", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "advancement", "Allows the user to give, remove, or check player advancements", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "attribute", "Allows the user to query, add, remove or set an entity attribute", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "ban", "Allows the user to add players to the ban list", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "ban-ip", "Allows the user to add ip address to the ban list", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "banlist", "Allows the user to display the ban list", PermissionDefault.OP, commands);
@@ -44,6 +44,7 @@ public final class CommandPermissions {
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "datapack", "Allows the user to control loaded data packs", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "debug", "Allows the user to start or stop a debugging session", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "deop", "Allows the user to revoke operator status from a player", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "dialog", "Allows the user to show dialogs", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "difficulty", "Allows the user to set the difficulty level", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "enchant", "Allows the user to enchant a player item", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "execute", "Allows the user to execute another command", PermissionDefault.OP, commands);
@@ -52,6 +53,7 @@ public final class CommandPermissions {
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "forceload", "Allows the user to force chunks to be constantly loaded or not", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "function", "Allows the user to run a function", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "gamerule", "Allows a user to set or query a game rule value", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "item", "Allows the user to replace items in inventories", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "jfr", "Allows a user to use the vanilla Java FlightRecorder profiling system", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "locate", "Allows the user to locate the closest structure", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "loot", "Allows the user to drop items from an inventory slot onto the ground", PermissionDefault.OP, commands);
@@ -60,11 +62,14 @@ public final class CommandPermissions {
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "pardon-ip", "Allows the user to remove entries from the ip address ban list", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "particle", "Allows the user to create particles", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "perf", "Allows the user to start/stop the vanilla performance metrics capture", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "place", "Allows the user to place features and structures", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "playsound", "Allows the user to play a sound", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "ride", "Allows the user to use the /ride command to control passengers", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "random", "Allows the user to generate a random number", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "recipe", "Allows the user to give or take recipes", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "reload", "Allows the user to reload loot tables, advancements, and functions from disk", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "item", "Allows the user to replace items in inventories", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "return", "Allows the user to use the /return command", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "ride", "Allows the user to use the /ride command to control passengers", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "rotate", "Allows the user to change the rotation of entities", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "save-all", "Allows the user to save the server to disk", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "save-off", "Allows the user disable automatic server saves", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "save-on", "Allows the user enable automatic server saves", PermissionDefault.OP, commands);
@@ -83,17 +88,15 @@ public final class CommandPermissions {
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "teammsg", "Allows the user to specify the message to send to team", PermissionDefault.TRUE, commands); // defaults to all players
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "tellraw", "Allows the user to display a JSON message to players", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "test", "Allows the user to manage and execute GameTests", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "time", "Allows the user to change or query the world's game time", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "tick", "Allows the user to control the tick rate of the server", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "time", "Allows the user to change or query the world's game time", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "title", "Allows the user to manage screen titles", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "transfer", "Allows the user to transfer to another server", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "version", "Shows info related to the server version", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "waypoint", "Allows the managment of a waypoints on the server/locator bar", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "weather", "Allows the user to set the weather", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "whitelist", "Allows the user to manage the server whitelist", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "worldborder", "Allows the user to manage the world border", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "place", "Allows the user to place features and structures", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "return", "Allows the user to use the /return command", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "random", "Allows the user to generate a random number", PermissionDefault.OP, commands);
DefaultPermissions.registerPermission(CommandPermissions.PREFIX + "rotate", "Allows the user to change the rotation of entities", PermissionDefault.OP, commands);
// Paper end
DefaultPermissions.registerPermission("minecraft.admin.command_feedback", "Receive command broadcasts when sendCommandFeedback is true", PermissionDefault.OP, commands);

View File

@@ -137,6 +137,10 @@ public class LegacyTest {
Material.RESIN_BRICK, Material.POTTED_OPEN_EYEBLOSSOM, Material.POTTED_CLOSED_EYEBLOSSOM,
// 1.21.5
Material.WILDFLOWERS, Material.LEAF_LITTER, Material.TEST_BLOCK, Material.TEST_INSTANCE_BLOCK, Material.BUSH, Material.FIREFLY_BUSH, Material.SHORT_DRY_GRASS, Material.TALL_DRY_GRASS, Material.CACTUS_FLOWER, Material.BLUE_EGG, Material.BROWN_EGG,
// 1.21.6
Material.BLACK_HARNESS, Material.BLUE_HARNESS, Material.BROWN_HARNESS, Material.CYAN_HARNESS, Material.DRIED_GHAST, Material.GRAY_HARNESS, Material.GREEN_HARNESS, Material.HAPPY_GHAST_SPAWN_EGG, Material.LIGHT_BLUE_HARNESS, Material.LIGHT_GRAY_HARNESS,
Material.LIME_HARNESS, Material.MAGENTA_HARNESS, Material.ORANGE_HARNESS, Material.PINK_HARNESS, Material.PURPLE_HARNESS, Material.RED_HARNESS, Material.WHITE_HARNESS, Material.YELLOW_HARNESS,
Material.MUSIC_DISC_TEARS,
//
Material.LEGACY_AIR, Material.LEGACY_DEAD_BUSH, Material.LEGACY_BURNING_FURNACE, Material.LEGACY_WALL_SIGN, Material.LEGACY_REDSTONE_TORCH_OFF, Material.LEGACY_SKULL, Material.LEGACY_REDSTONE_COMPARATOR_ON, Material.LEGACY_WALL_BANNER, Material.LEGACY_MONSTER_EGG));

View File

@@ -69,9 +69,9 @@ public class ApiVersionTest {
public void testCurrentVersionUpdated() {
ApiVersion apiVersionOne = null;
try {
apiVersionOne = ApiVersion.getOrCreateVersion(SharedConstants.getCurrentVersion().getName());
apiVersionOne = ApiVersion.getOrCreateVersion(SharedConstants.getCurrentVersion().name());
} catch (IllegalArgumentException ex) {
if (!SharedConstants.getCurrentVersion().isStable()) {
if (!SharedConstants.getCurrentVersion().stable()) {
return;
}
}