|
16 | 16 | import com.laytonsmith.abstraction.MCCreatureSpawner; |
17 | 17 | import com.laytonsmith.abstraction.MCCrossbowMeta; |
18 | 18 | import com.laytonsmith.abstraction.MCEnchantmentStorageMeta; |
| 19 | +import com.laytonsmith.abstraction.MCEquippableComponent; |
19 | 20 | import com.laytonsmith.abstraction.MCFireworkBuilder; |
20 | 21 | import com.laytonsmith.abstraction.MCFireworkEffect; |
21 | 22 | import com.laytonsmith.abstraction.MCFireworkEffectMeta; |
|
108 | 109 | import com.laytonsmith.core.natives.interfaces.Mixed; |
109 | 110 |
|
110 | 111 | import java.util.ArrayList; |
| 112 | +import java.util.Collection; |
111 | 113 | import java.util.HashMap; |
112 | 114 | import java.util.List; |
113 | 115 | import java.util.Locale; |
@@ -566,6 +568,39 @@ public Construct itemMeta(MCItemStack is, Target t) { |
566 | 568 | if(meta.hasTooltipStyle()) { |
567 | 569 | ma.set("tooltipstyle", new CString(meta.getTooltipStyle(), t), t); |
568 | 570 | } |
| 571 | + if(meta.hasEquippable()) { |
| 572 | + MCEquippableComponent equippableComponent = meta.getEquippable(); |
| 573 | + CArray equippable = CArray.GetAssociativeArray(t); |
| 574 | + MCEquipmentSlot slot = equippableComponent.getSlot(); |
| 575 | + equippable.set("slot", new CString(slot.name(), t), t); |
| 576 | + String asset = equippableComponent.getAssetId(); |
| 577 | + if(asset != null) { |
| 578 | + equippable.set("asset", new CString(asset, t), t); |
| 579 | + } |
| 580 | + String cameraOverlay = equippableComponent.getCameraOverlay(); |
| 581 | + if(cameraOverlay != null) { |
| 582 | + equippable.set("overlay", new CString(cameraOverlay, t), t); |
| 583 | + } |
| 584 | + Collection<MCEntityType> allowedEntities = equippableComponent.getAllowedEntities(); |
| 585 | + if(allowedEntities != null) { |
| 586 | + CArray entities = new CArray(t); |
| 587 | + for(MCEntityType type : allowedEntities) { |
| 588 | + entities.push(new CString(type.name(), t), t); |
| 589 | + } |
| 590 | + equippable.set("entities", entities, t); |
| 591 | + } |
| 592 | + String sound = equippableComponent.getEquipSound(); |
| 593 | + if(sound != null) { |
| 594 | + equippable.set("sound", new CString(sound, t), t); |
| 595 | + } |
| 596 | + equippable.set("dispensable", CBoolean.get(equippableComponent.isDispensable()), t); |
| 597 | + equippable.set("swappable", CBoolean.get(equippableComponent.isSwappable()), t); |
| 598 | + equippable.set("damageable", CBoolean.get(equippableComponent.isDamageOnHurt()), t); |
| 599 | + if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21_5)) { |
| 600 | + equippable.set("interactable", CBoolean.get(equippableComponent.isEquipOnInteract()), t); |
| 601 | + } |
| 602 | + ma.set("equippable", equippable, t); |
| 603 | + } |
569 | 604 | } |
570 | 605 |
|
571 | 606 | } else { // versions before 1.20.6 |
@@ -1190,6 +1225,78 @@ public MCItemMeta itemMeta(Mixed c, MCMaterial mat, Target t) throws ConfigRunti |
1190 | 1225 | meta.setTooltipStyle(tooltipstyle.val()); |
1191 | 1226 | } |
1192 | 1227 | } |
| 1228 | + if(ma.containsKey("equippable")) { |
| 1229 | + Mixed equippableMixed = ma.get("equippable", t); |
| 1230 | + if(equippableMixed instanceof CNull) { |
| 1231 | + // not yet supported |
| 1232 | + } else if(equippableMixed.isInstanceOf(CArray.TYPE)) { |
| 1233 | + CArray equippableArray = (CArray) equippableMixed; |
| 1234 | + if(!equippableArray.isAssociative()) { |
| 1235 | + throw new CREFormatException("Equippable array must be associative.", t); |
| 1236 | + } |
| 1237 | + MCEquippableComponent equippable = meta.getEquippable(); |
| 1238 | + try { |
| 1239 | + String slotName = equippableArray.get("slot", t).val().toUpperCase(); |
| 1240 | + equippable.setSlot(MCEquipmentSlot.valueOf(slotName)); |
| 1241 | + } catch (IllegalArgumentException ex) { |
| 1242 | + throw new CREFormatException("Not a valid equipment slot: " |
| 1243 | + + equippableArray.get("slot", t).val(), t); |
| 1244 | + } |
| 1245 | + if(equippableArray.containsKey("entities")) { |
| 1246 | + Mixed entitiesMixed = equippableArray.get("entities", t); |
| 1247 | + if(entitiesMixed instanceof CNull) { |
| 1248 | + // ignored |
| 1249 | + } else if(entitiesMixed.isInstanceOf(CArray.TYPE)) { |
| 1250 | + CArray entitiesArray = (CArray) entitiesMixed; |
| 1251 | + if(entitiesArray.isAssociative()) { |
| 1252 | + throw new CREFormatException("Allowed entities array must not be associative.", t); |
| 1253 | + } |
| 1254 | + Collection<MCEntityType> allowedEntities = new ArrayList<>(); |
| 1255 | + for(Mixed type : entitiesArray) { |
| 1256 | + allowedEntities.add(MCEntityType.valueOf(type.val())); |
| 1257 | + } |
| 1258 | + equippable.setAllowedEntities(allowedEntities); |
| 1259 | + } |
| 1260 | + } |
| 1261 | + if(equippableArray.containsKey("overlay")) { |
| 1262 | + Mixed cameraOverlayMixed = equippableArray.get("overlay", t); |
| 1263 | + if(!(cameraOverlayMixed instanceof CNull)) { |
| 1264 | + equippable.setCameraOverlay(cameraOverlayMixed.val()); |
| 1265 | + } |
| 1266 | + } |
| 1267 | + if(equippableArray.containsKey("damageable")) { |
| 1268 | + equippable.setDamageOnHurt(ArgumentValidation.getBooleanObject( |
| 1269 | + equippableArray.get("damageable", t), t)); |
| 1270 | + } |
| 1271 | + if(equippableArray.containsKey("dispensable")) { |
| 1272 | + equippable.setDispensable(ArgumentValidation.getBooleanObject( |
| 1273 | + equippableArray.get("dispensable", t), t)); |
| 1274 | + } |
| 1275 | + if(equippableArray.containsKey("asset")) { |
| 1276 | + Mixed assetMixed = equippableArray.get("asset", t); |
| 1277 | + if(!(assetMixed instanceof CNull)) { |
| 1278 | + equippable.setAssetId(assetMixed.val()); |
| 1279 | + } |
| 1280 | + } |
| 1281 | + if(equippableArray.containsKey("sound")) { |
| 1282 | + Mixed soundMixed = equippableArray.get("sound", t); |
| 1283 | + if(!(soundMixed instanceof CNull)) { |
| 1284 | + equippable.setEquipSound(soundMixed.val()); |
| 1285 | + } |
| 1286 | + } |
| 1287 | + if(equippableArray.containsKey("swappable")) { |
| 1288 | + equippable.setSwappable(ArgumentValidation.getBooleanObject(equippableArray.get("swappable", t), t)); |
| 1289 | + } |
| 1290 | + if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_21_5)) { |
| 1291 | + if(equippableArray.containsKey("interactable")) { |
| 1292 | + equippable.setEquipOnInteract(ArgumentValidation.getBooleanObject(equippableArray.get("interactable", t), t)); |
| 1293 | + } |
| 1294 | + } |
| 1295 | + meta.setEquippable(equippable); |
| 1296 | + } else { |
| 1297 | + throw new CREFormatException("Expected an array for item equippable component.", t); |
| 1298 | + } |
| 1299 | + } |
1193 | 1300 | } |
1194 | 1301 | if(ma.containsKey("damage")) { |
1195 | 1302 | Mixed damage = ma.get("damage", t); |
|
0 commit comments