Skip to content

Commit

Permalink
Add support for Minecraft 1.21
Browse files Browse the repository at this point in the history
Attribute modifiers' optional "name" and "uuid" keys have been replaced with a namespaced key under "id". Old attribute modifiers will use the UUID to generate a namespaced key.
  • Loading branch information
PseudoKnight committed Jun 15, 2024
1 parent 25f8cd8 commit 5b137ff
Show file tree
Hide file tree
Showing 23 changed files with 216 additions and 54 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
<!-- GPL -->
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.6-R0.1-SNAPSHOT</version>
<version>1.21-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/Convertor.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public interface Convertor {

MCAttributeModifier GetAttributeModifier(MCAttribute attr, UUID id, String name, double amt, MCAttributeModifier.Operation op, MCEquipmentSlotGroup slot);

MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlot slot);

MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlotGroup slot);

void Startup(CommandHelperPlugin chp);

MCMaterial[] GetMaterialValues();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.UUID;

public interface MCAttributeModifier extends AbstractionObject {
MCNamespacedKey getKey();
String getAttributeName();
MCAttribute getAttribute();
MCEquipmentSlot getEquipmentSlot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,12 @@ public enum MCVanillaMaterial {
GUSTER_POTTERY_SHERD(MCVersion.MC1_20_6),
SCRAPE_POTTERY_SHERD(MCVersion.MC1_20_6),
VAULT(MCVersion.MC1_20_6),
WIND_CHARGE(MCVersion.MC1_20_6);
WIND_CHARGE(MCVersion.MC1_20_6),

// 1.21 additions
MUSIC_DISC_CREATOR(MCVersion.MC1_21),
MUSIC_DISC_CREATOR_MUSIC_BOX(MCVersion.MC1_21),
MUSIC_DISC_PRECIPICE(MCVersion.MC1_21);

private final MCVersion since;
private final MCVersion until;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
import org.bukkit.inventory.BlastingRecipe;
import org.bukkit.inventory.CampfireRecipe;
import org.bukkit.inventory.ComplexRecipe;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.InventoryHolder;
Expand Down Expand Up @@ -321,6 +322,23 @@ public MCAttributeModifier GetAttributeModifier(MCAttribute attr, UUID id, Strin
return new BukkitMCAttributeModifier(BukkitMCAttribute.getConvertor().getConcreteEnum(attr), mod);
}

@Override
public MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlot slot) {
EquipmentSlot es = BukkitMCEquipmentSlot.getConvertor().getConcreteEnum(slot);
AttributeModifier mod = new AttributeModifier((NamespacedKey) key.getHandle(), amt,
BukkitMCAttributeModifier.Operation.getConvertor().getConcreteEnum(op),
es == null ? EquipmentSlotGroup.ANY : es.getGroup());
return new BukkitMCAttributeModifier(BukkitMCAttribute.getConvertor().getConcreteEnum(attr), mod);
}

@Override
public MCAttributeModifier GetAttributeModifier(MCAttribute attr, MCNamespacedKey key, double amt, MCAttributeModifier.Operation op, MCEquipmentSlotGroup slot) {
AttributeModifier mod = new AttributeModifier((NamespacedKey) key.getHandle(), amt,
BukkitMCAttributeModifier.Operation.getConvertor().getConcreteEnum(op),
EquipmentSlotGroup.getByName(slot.name()));
return new BukkitMCAttributeModifier(BukkitMCAttribute.getConvertor().getConcreteEnum(attr), mod);
}

@Override
public MCMetadataValue GetMetadataValue(Object value, MCPlugin plugin) {
return new BukkitMCMetadataValue(new FixedMetadataValue(((BukkitMCPlugin) plugin).getHandle(), value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.laytonsmith.abstraction.Implementation;
import com.laytonsmith.abstraction.MCAttributeModifier;
import com.laytonsmith.abstraction.MCNamespacedKey;
import com.laytonsmith.abstraction.enums.EnumConvertor;
import com.laytonsmith.abstraction.enums.MCAttribute;
import com.laytonsmith.abstraction.enums.MCEquipmentSlot;
Expand Down Expand Up @@ -31,6 +32,11 @@ public Object getHandle() {
return am;
}

@Override
public MCNamespacedKey getKey() {
return new BukkitMCNamespacedKey(am.getKey());
}

@Override
public String getAttributeName() {
return am.getName();
Expand Down
41 changes: 35 additions & 6 deletions src/main/java/com/laytonsmith/abstraction/enums/MCArt.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,63 @@

@MEnum("com.commandhelper.Art")
public enum MCArt {
// 1x1
KEBAB,
AZTEC,
ALBAN,
AZTEC2,
BOMB,
PLANT,
WASTELAND,
MEDITATIVE,
// 2x1
POOL,
COURBET,
SEA,
SUNSET,
CREEBET,
// 1x2
WANDERER,
GRAHAM,
PRAIRIE_RIDE,
// 2x2
MATCH,
BUST,
STAGE,
VOID,
SKULL_AND_ROSES,
WITHER,
BAROQUE,
HUMBLE,
EARTH,
WIND,
WATER,
FIRE,
// 4x2
FIGHTERS,
CHANGING,
FINDING,
LOWMIST,
PASSAGE,
// 3x3
BOUQUET,
CAVEBIRD,
COTAN,
ENDBOSS,
FERN,
OWLEMONS,
SUNFLOWERS,
TIDES,
// 4x3
SKELETON,
DONKEY_KONG,
// 3x4
BACKYARD,
POND,
// 4x4
POINTER,
PIGSCENE,
BURNING_SKULL,
SKELETON,
DONKEY_KONG,
EARTH,
WIND,
WATER,
FIRE
ORB,
UNPACKED,
}
11 changes: 10 additions & 1 deletion src/main/java/com/laytonsmith/abstraction/enums/MCAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public enum MCAttribute {
GENERIC_ATTACK_DAMAGE,
GENERIC_ATTACK_KNOCKBACK,
GENERIC_ATTACK_SPEED,
GENERIC_BURNING_TIME,
GENERIC_EXPLOSION_KNOCKBACK_RESISTANCE,
GENERIC_FALL_DAMAGE_MULTIPLIER,
GENERIC_FLYING_SPEED,
GENERIC_FOLLOW_RANGE,
Expand All @@ -18,13 +20,20 @@ public enum MCAttribute {
GENERIC_LUCK,
GENERIC_MAX_ABSORPTION,
GENERIC_MAX_HEALTH,
GENERIC_MOVEMENT_EFFICIENCY,
GENERIC_MOVEMENT_SPEED,
GENERIC_OXYGEN_BONUS,
GENERIC_SAFE_FALL_DISTANCE,
GENERIC_SCALE,
GENERIC_STEP_HEIGHT,
HORSE_JUMP_STRENGTH, // changed to GENERIC_JUMP_STRENGTH
GENERIC_WATER_MOVEMENT_EFFICIENCY,
HORSE_JUMP_STRENGTH, // changed to GENERIC_JUMP_STRENGTH in 1.20.6
PLAYER_BLOCK_BREAK_SPEED,
PLAYER_BLOCK_INTERACTION_RANGE,
PLAYER_ENTITY_INTERACTION_RANGE,
PLAYER_MINING_EFFICIENCY,
PLAYER_SNEAKING_SPEED,
PLAYER_SUBMERGED_MINING_SPEED,
PLAYER_SWEEPING_DAMAGE_RATIO,
ZOMBIE_SPAWN_REINFORCEMENTS
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public enum MCDamageCause {
* Damage caused when an entity steps on MAGMA.
*/
HOT_FLOOR,
/**
* Damage caused when an entity is on top a campfire.
*/
CAMPFIRE,
/**
* Damage caused when an entity is colliding with too many entities due to the maxEntityCramming game rule.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public enum MCPatternShape {
DIAGONAL_LEFT_MIRROR,
DIAGONAL_RIGHT,
DIAGONAL_RIGHT_MIRROR,
FLOW,
FLOWER,
GLOBE,
GRADIENT,
GRADIENT_UP,
GUSTER,
HALF_HORIZONTAL,
HALF_HORIZONTAL_MIRROR,
HALF_VERTICAL,
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/laytonsmith/abstraction/enums/MCSound.java
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,8 @@ public enum MCVanillaSound {
BLOCK_HEAVY_CORE_PLACE(MCVersion.MC1_20_6),
BLOCK_HEAVY_CORE_STEP(MCVersion.MC1_20_6),
BLOCK_TRIAL_SPAWNER_ABOUT_TO_SPAWN_ITEM(MCVersion.MC1_20_6),
BLOCK_TRIAL_SPAWNER_AMBIENT_CHARGED(MCVersion.MC1_20_6),
BLOCK_TRIAL_SPAWNER_AMBIENT_CHARGED(MCVersion.MC1_20_6, MCVersion.MC1_20_6),
BLOCK_TRIAL_SPAWNER_AMBIENT_OMINOUS(MCVersion.MC1_21), // changed from BLOCK_TRIAL_SPAWNER_AMBIENT_CHARGED
BLOCK_TRIAL_SPAWNER_CHARGE_ACTIVATE(MCVersion.MC1_20_6),
BLOCK_TRIAL_SPAWNER_SPAWN_ITEM(MCVersion.MC1_20_6),
BLOCK_TRIAL_SPAWNER_SPAWN_ITEM_BEGIN(MCVersion.MC1_20_6),
Expand Down Expand Up @@ -1707,6 +1708,13 @@ public enum MCVanillaSound {
ITEM_WOLF_ARMOR_DAMAGE(MCVersion.MC1_20_6),
ITEM_WOLF_ARMOR_REPAIR(MCVersion.MC1_20_6),

// 1.21 additions
BLOCK_TRIAL_SPAWNER_OMINOUS_ACTIVATE(MCVersion.MC1_21),
BLOCK_VAULT_REJECT_REWARDED_PLAYER(MCVersion.MC1_21),
MUSIC_DISC_CREATOR(MCVersion.MC1_21),
MUSIC_DISC_CREATOR_MUSIC_BOX(MCVersion.MC1_21),
MUSIC_DISC_PRECIPICE(MCVersion.MC1_21),

UNKNOWN(MCVersion.NEVER);

private final MCVersion since;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ public enum MCSpawnReason {
SPELL,
METAMORPHOSIS,
DUPLICATION,
ENCHANTMENT,
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum MCTreeType {
DARK_OAK,
COCOA_TREE,
MEGA_REDWOOD,
MEGA_PINE,
TALL_BIRCH,
CHORUS_PLANT,
CRIMSON_FUNGUS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public enum MCVersion implements Version {
MC1_20_4,
MC1_20_6,
MC1_20_X,
MC1_21,
MC1_21_X,
MC1_X,
MC2_X,
MCX_X,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface MCLightningStrikeEvent extends MCWeatherEvent {
enum Cause {
COMMAND,
CUSTOM,
ENCHANTMENT,
SPAWNER,
TRIDENT,
TRAP,
Expand Down
57 changes: 37 additions & 20 deletions src/main/java/com/laytonsmith/core/ObjectGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1736,10 +1736,16 @@ public Map<MCEnchantment, Integer> enchants(CArray enchantArray, Target t) {

public CArray attributeModifier(MCAttributeModifier m, Target t) {
CArray modifier = CArray.GetAssociativeArray(t);

if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21)) {
modifier.set("id", m.getKey().toString());
} else {
modifier.set("name", m.getAttributeName());
modifier.set("uuid", m.getUniqueId().toString());
}

modifier.set("attribute", m.getAttribute().name());
modifier.set("name", m.getAttributeName());
modifier.set("operation", m.getOperation().name());
modifier.set("uuid", m.getUniqueId().toString());
modifier.set("amount", new CDouble(m.getAmount(), t), t);

Mixed slot = CNull.NULL;
Expand Down Expand Up @@ -1767,8 +1773,10 @@ public MCAttributeModifier attributeModifier(CArray m, Target t) {
MCAttribute attribute;
MCAttributeModifier.Operation operation;
double amount;
MCNamespacedKey id = null;
UUID uuid = null;
String name = "";
MCEquipmentSlotGroup slotGroup = null;
MCEquipmentSlot slot = null;

try {
Expand All @@ -1785,43 +1793,52 @@ public MCAttributeModifier attributeModifier(CArray m, Target t) {

amount = ArgumentValidation.getDouble(m.get("amount", t), t);

if(m.containsKey("name")) {
name = m.get("name", t).val();
}

if(m.containsKey("uuid")) {
try {
uuid = UUID.fromString(m.get("uuid", t).val());
} catch (IllegalArgumentException ex) {
throw new CREFormatException("Invalid UUID format: " + m.get("uuid", t), t);
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21) && m.containsKey("id")) {
id = StaticLayer.GetConvertor().GetNamespacedKey(m.get("id", t).val());
} else {
if(m.containsKey("name")) {
name = m.get("name", t).val();
}
if(m.containsKey("uuid")) {
try {
uuid = UUID.fromString(m.get("uuid", t).val());
} catch (IllegalArgumentException ex) {
throw new CREFormatException("Invalid UUID format: " + m.get("uuid", t), t);
}
}
}

if(m.containsKey("slot")) {
Mixed s = m.get("slot", t);
if(!(s instanceof CNull)) {
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_20_6)) {
MCEquipmentSlotGroup slotGroup = null;
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;
}
if(slotGroup != null) {
return StaticLayer.GetConvertor().GetAttributeModifier(attribute, uuid, name, amount, operation,
slotGroup);
}
}
try {
slot = MCEquipmentSlot.valueOf(s.val());
} catch (IllegalArgumentException ex) {
throw new CREFormatException("Invalid equipment slot name: " + m.get("slot", t), t);
if(slotGroup == null) {
try {
slot = MCEquipmentSlot.valueOf(s.val());
} catch (IllegalArgumentException ex) {
throw new CREFormatException("Invalid equipment slot name: " + m.get("slot", t), t);
}
}
}
}

if(slotGroup != null) {
if(id != null) {
return StaticLayer.GetConvertor().GetAttributeModifier(attribute, id, amount, operation, slotGroup);
}
return StaticLayer.GetConvertor().GetAttributeModifier(attribute, uuid, name, amount, operation, slotGroup);
}
if(id != null) {
return StaticLayer.GetConvertor().GetAttributeModifier(attribute, id, amount, operation, slot);
}
return StaticLayer.GetConvertor().GetAttributeModifier(attribute, uuid, name, amount, operation, slot);
}

Expand Down
Loading

0 comments on commit 5b137ff

Please sign in to comment.