Skip to content

Commit

Permalink
Add missing BODY equipment slot group
Browse files Browse the repository at this point in the history
Spigot is missing the BODY slot from vanilla, but we want to still support it in Paper. Falls back to ARMOR in Spigot.
  • Loading branch information
PseudoKnight committed Sep 2, 2024
1 parent 7a5dd5b commit 36070ef
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public MCPotionData GetPotionData(MCPotionType type, boolean extended, boolean u
new Class[]{PotionType.class, boolean.class, boolean.class},
new Object[]{type.getConcrete(), extended, upgraded}));
} catch (ClassNotFoundException ex) {
// probably before 1.20.5
// probably after 1.20.5
// use PotionType instead
return null;
}
Expand All @@ -313,6 +313,12 @@ public MCAttributeModifier GetAttributeModifier(MCAttribute attr, UUID id, Strin

@Override
public MCAttributeModifier GetAttributeModifier(MCAttribute attr, UUID id, String name, double amt, MCAttributeModifier.Operation op, MCEquipmentSlotGroup slot) {
if(!((BukkitMCServer) Static.getServer()).isPaper()) {
// BODY is missing from Spigot, so this falls back to ARMOR just like EquipmentSlot.BODY
if(slot == MCEquipmentSlotGroup.BODY) {
slot = MCEquipmentSlotGroup.ARMOR;
}
}
if(id == null) {
id = UUID.randomUUID();
}
Expand All @@ -333,6 +339,12 @@ public MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKe

@Override
public MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlotGroup slot) {
if(!((BukkitMCServer) Static.getServer()).isPaper()) {
// BODY is missing from Spigot, so this falls back to ARMOR just like EquipmentSlot.BODY
if(slot == MCEquipmentSlotGroup.BODY) {
slot = MCEquipmentSlotGroup.ARMOR;
}
}
AttributeModifier mod = new AttributeModifier((NamespacedKey) key.getHandle(), amt,
BukkitMCAttributeModifier.Operation.getConvertor().getConcreteEnum(op),
EquipmentSlotGroup.getByName(slot.name()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public MCEquipmentSlotGroup getEquipmentSlotGroup() {
return MCEquipmentSlotGroup.ARMOR;
} else if(slotGroup == EquipmentSlotGroup.HAND) {
return MCEquipmentSlotGroup.HAND;
} else if(slotGroup.toString().equals("body")) { // BODY slot group is missing from Spigot
return MCEquipmentSlotGroup.BODY;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum MCEquipmentSlotGroup {
ANY,
HAND,
ARMOR
ARMOR,
BODY
}
15 changes: 8 additions & 7 deletions src/main/java/com/laytonsmith/core/ObjectGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1812,13 +1812,14 @@ public MCAttributeModifier attributeModifier(CArray m, Target t) {
Mixed s = m.get("slot", t);
if(!(s instanceof CNull)) {
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_20_6)) {
if(s.val().equals("ANY")) {
slotGroup = MCEquipmentSlotGroup.ANY;
} else if(s.val().equals("HAND")) {
slotGroup = MCEquipmentSlotGroup.HAND;
} else if(s.val().equals("ARMOR")) {
slotGroup = MCEquipmentSlotGroup.ARMOR;
}
// check new slots groups first
slotGroup = switch(s.val()) {
case "ANY" -> MCEquipmentSlotGroup.ANY;
case "HAND" -> MCEquipmentSlotGroup.HAND;
case "ARMOR" -> MCEquipmentSlotGroup.ARMOR;
case "BODY" -> MCEquipmentSlotGroup.BODY;
default -> null;
};
}
if(slotGroup == null) {
try {
Expand Down

0 comments on commit 36070ef

Please sign in to comment.