Skip to content
Permalink
Browse files

add trident weapon support for 1.13

  • Loading branch information...
mcmonkey4eva committed May 5, 2019
1 parent 69057f5 commit c74f82eec150dbfe1832f52bf6672191793a1b56
@@ -190,6 +190,7 @@ These are all valid targets and ignores:
- Swords/tools
- Bow
- equip NPC with arrows of any given type in their `/npc inventory` to set fired arrow type!
- Trident (will be thrown)
- Blaze rod (shoots fire balls!)
- Potions (splash, lingering)
- Nether star (strikes lightning!)
@@ -154,15 +154,33 @@ else if (itemHelper.usesSnowball()) {
return false;
}
sentinel.timeSinceAttack = 0;
ItemStack item = itemHelper.getArrow();
if (item != null) {
weaponHelper.fireSnowball(entity.getEyeLocation());
if (sentinel.needsAmmo) {
itemHelper.takeSnowball();
itemHelper.grabNextItem();
weaponHelper.fireSnowball(entity.getEyeLocation());
if (sentinel.needsAmmo) {
itemHelper.takeOne();
itemHelper.grabNextItem();
}
return true;
}
else if (sentinel.rangedChase) {
chase(entity);
return false;
}
}
else if (itemHelper.usesTrident()) {
if (targetingHelper.canSee(entity)) {
if (sentinel.timeSinceAttack < sentinel.attackRateRanged) {
if (sentinel.rangedChase) {
rechase();
}
return true;
return false;
}
sentinel.timeSinceAttack = 0;
weaponHelper.fireTrident(entity.getEyeLocation());
if (sentinel.needsAmmo) {
itemHelper.takeOne();
itemHelper.grabNextItem();
}
return true;
}
else if (sentinel.rangedChase) {
chase(entity);
@@ -97,37 +97,6 @@ public void takeArrow() {
}
}


/**
* Takes a snowball from the NPC's inventory.
*/
public void takeSnowball() {
if (!getNPC().hasTrait(Inventory.class)) {
return;
}
Inventory inv = getNPC().getTrait(Inventory.class);
ItemStack[] items = inv.getContents();
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item != null) {
Material mat = item.getType();
if (mat == SentinelTarget.MATERIAL_SNOW_BALL) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
items[i] = item;
inv.setContents(items);
return;
}
else {
items[i] = null;
inv.setContents(items);
return;
}
}
}
}
}

/**
* Takes one item from the NPC's held items (for consumables).
*/
@@ -337,6 +306,17 @@ public boolean usesWitherSkull() {
return it != null && SentinelTarget.SKULL_MATERIALS.contains(it.getType());
}

/**
* Returns whether the NPC is using a trident item.
*/
public boolean usesTrident() {
if (!SentinelTarget.v1_13) {
return false;
}
ItemStack it = getHeldItem();
return it != null && it.getType() == Material.TRIDENT;
}

/**
* Returns whether the NPC is using a spectral-effect-attack item.
*/
@@ -125,6 +125,26 @@ public void fireSnowball(Location target) {
ent.setVelocity(sentinel.fixForAcc(target.clone().subtract(spawnAt).toVector().normalize().multiply(2.0))); // TODO: Fiddle with '2.0'.
}

/**
* Fires a trident from the NPC at a target.
*/
public void fireTrident(Location target) {
if (!SentinelTarget.v1_13) {
return;
}
sentinel.swingWeapon();
sentinel.stats_arrowsFired++;
sentinel.faceLocation(target);
Vector forward = getLivingEntity().getEyeLocation().getDirection();
Location spawnAt = getLivingEntity().getEyeLocation().clone().add(forward.clone().multiply(sentinel.firingMinimumRange() + 2));
Trident ent = (Trident) spawnAt.getWorld().spawnEntity(spawnAt, EntityType.TRIDENT);
if (SentinelTarget.v1_14) {
ent.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
}
ent.setShooter(getLivingEntity());
ent.setVelocity(sentinel.fixForAcc(target.clone().subtract(spawnAt).toVector().normalize().multiply(2.0))); // TODO: Fiddle with '2.0'.
}

/**
* Fires an egg from the NPC at a target.
*/
@@ -328,6 +328,7 @@ public static boolean isWeapon(Material mat) {
WEAPON_DAMAGE_MULTIPLIERS.put(getMaterial("STONE_SWORD"), 5.0);
WEAPON_DAMAGE_MULTIPLIERS.put(getMaterial("GOLDEN_SWORD"), 4.0);
WEAPON_DAMAGE_MULTIPLIERS.put(getMaterial("WOODEN_SWORD"), 4.0);
WEAPON_DAMAGE_MULTIPLIERS.put(getMaterial("TRIDENT"), 8.0);
// Pickaxe
addAllMaterials(PICKAXE_MATERIALS, "DIAMOND_PICKAXE", "IRON_PICKAXE", "STONE_PICKAXE", "GOLDEN_PICKAXE", "WOODEN_PICKAXE");
allMaterialsTo(WEAPON_DAMAGE_MULTIPLIERS, PICKAXE_MATERIALS, 2.0);

0 comments on commit c74f82e

Please sign in to comment.
You can’t perform that action at this time.