Skip to content

Commit

Permalink
Add arrow pickup status to entity_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Oct 17, 2023
1 parent 5c7003c commit be735bb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPotionEffectType;
import com.laytonsmith.core.Static;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.potion.PotionData;
Expand Down Expand Up @@ -105,4 +106,14 @@ public int getPierceLevel() {
public void setPierceLevel(int level) {
arrow.setPierceLevel(level);
}

@Override
public MCArrow.PickupStatus getPickupStatus() {
return MCArrow.PickupStatus.valueOf(arrow.getPickupStatus().name());
}

@Override
public void setPickupStatus(MCArrow.PickupStatus status) {
arrow.setPickupStatus(AbstractArrow.PickupStatus.valueOf(status.name()));
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/entities/MCArrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ public interface MCArrow extends MCProjectile {
int getPierceLevel();

void setPierceLevel(int level);

PickupStatus getPickupStatus();

void setPickupStatus(PickupStatus status);

enum PickupStatus {
ALLOWED,
DISALLOWED,
CREATIVE_ONLY
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/EntityManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -1866,6 +1866,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
specArray.set(entity_spec.KEY_ARROW_KNOCKBACK, new CInt(arrow.getKnockbackStrength(), t), t);
specArray.set(entity_spec.KEY_ARROW_DAMAGE, new CDouble(arrow.getDamage(), t), t);
specArray.set(entity_spec.KEY_ARROW_PIERCE_LEVEL, new CInt(arrow.getPierceLevel(), t), t);
specArray.set(entity_spec.KEY_ARROW_PICKUP, new CString(arrow.getPickupStatus().name(), t), t);
CArray tippedmeta = CArray.GetAssociativeArray(t);
CArray tippedeffects = ObjectGenerator.GetGenerator().potions(arrow.getCustomEffects(), t);
tippedmeta.set("potions", tippedeffects, t);
Expand Down Expand Up @@ -2329,6 +2330,7 @@ public MSVersion since() {
private static final String KEY_ARROW_KNOCKBACK = "knockback";
private static final String KEY_ARROW_DAMAGE = "damage";
private static final String KEY_ARROW_PIERCE_LEVEL = "piercelevel";
private static final String KEY_ARROW_PICKUP = "pickup";
private static final String KEY_ARMORSTAND_ARMS = "arms";
private static final String KEY_ARMORSTAND_BASEPLATE = "baseplate";
private static final String KEY_ARMORSTAND_GRAVITY = "gravity";
Expand Down Expand Up @@ -2655,6 +2657,14 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
}
arrow.setPierceLevel(level);
break;
case entity_spec.KEY_ARROW_PICKUP:
try {
arrow.setPickupStatus(MCArrow.PickupStatus.valueOf(specArray.get(index, t).val()));
} catch (IllegalArgumentException ex) {
throw new CREFormatException("Invalid arrow pickup status: "
+ specArray.get(index, t).val(), t);
}
break;
case entity_spec.KEY_TIPPEDARROW_POTIONMETA:
Mixed c = specArray.get(index, t);
if(c.isInstanceOf(CArray.TYPE)) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/functionDocs/entity_spec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This particle array must contain a "particle" key, and supports the keys "block"
* %KEY_ARROW_KNOCKBACK%: The knockback strength. (int)
* %KEY_ARROW_DAMAGE%: The amount of damage. (double)
* %KEY_ARROW_PIERCE_LEVEL%: The remaining times that this arrow can pierce through an entity. (int from 0 and 127)
* %KEY_ARROW_PICKUP%: Whether picking up this arrow is ALLOWED, DISALLOWED, or CREATIVE_ONLY.
* %KEY_TIPPEDARROW_POTIONMETA%: An associative array with a "base" potion array and a "potions" array of effect arrays for a tipped arrow.
|-
| ARMOR_STAND
Expand Down

0 comments on commit be735bb

Please sign in to comment.