Refactor mount spawning due to API changes; fixes an exception thrown when trying to use barding on non-normal horses.
This commit adds support for llamas and removes barding and saddles from non-horse mounts.
This commit is contained in:
@@ -827,51 +827,58 @@ public class ArenaImpl implements Arena
|
|||||||
int amount = inv.getItem(hay).getAmount();
|
int amount = inv.getItem(hay).getAmount();
|
||||||
|
|
||||||
// Variant
|
// Variant
|
||||||
Horse.Variant variant = Horse.Variant.HORSE;
|
EntityType type = horseTypeFromAmount(amount);
|
||||||
switch (amount % 8) {
|
|
||||||
case 2: variant = Horse.Variant.DONKEY; break;
|
|
||||||
case 3: variant = Horse.Variant.MULE; break;
|
|
||||||
case 4: variant = Horse.Variant.SKELETON_HORSE; break;
|
|
||||||
case 5: variant = Horse.Variant.UNDEAD_HORSE; break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Barding
|
|
||||||
Material barding = null;
|
|
||||||
switch ((amount >> 3) % 4) {
|
|
||||||
case 1: barding = Material.IRON_BARDING; break;
|
|
||||||
case 2: barding = Material.GOLD_BARDING; break;
|
|
||||||
case 3: barding = Material.DIAMOND_BARDING; break;
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Spawn the horse, set its variant, tame it, etc.
|
// Spawn the horse, set its variant, tame it, etc.
|
||||||
Horse horse = (Horse) world.spawnEntity(p.getLocation(), EntityType.HORSE);
|
AbstractHorse mount = (AbstractHorse) world.spawnEntity(p.getLocation(), type);
|
||||||
if (MobArena.random.nextInt(20) == 0) {
|
if (MobArena.random.nextInt(20) == 0) {
|
||||||
horse.setBaby();
|
mount.setBaby();
|
||||||
} else {
|
} else {
|
||||||
horse.setAdult();
|
mount.setAdult();
|
||||||
}
|
}
|
||||||
horse.setVariant(variant);
|
mount.setTamed(true);
|
||||||
horse.setTamed(true);
|
mount.setOwner(p);
|
||||||
horse.setOwner(p);
|
mount.setPassenger(p);
|
||||||
horse.setPassenger(p);
|
mount.setHealth(mount.getMaxHealth());
|
||||||
horse.setHealth(horse.getMaxHealth());
|
|
||||||
|
|
||||||
// Give it a saddle and possibly barding
|
// If normal horse, barding and saddle
|
||||||
horse.getInventory().setSaddle(new ItemStack(Material.SADDLE));
|
if (type == EntityType.HORSE) {
|
||||||
if (barding != null) {
|
Horse horse = (Horse) mount;
|
||||||
horse.getInventory().setArmor(new ItemStack(barding));
|
horse.getInventory().setSaddle(new ItemStack(Material.SADDLE));
|
||||||
|
Material barding = bardingFromAmount(amount);
|
||||||
|
if (barding != null) {
|
||||||
|
horse.getInventory().setArmor(new ItemStack(barding));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to monster manager
|
// Add to monster manager
|
||||||
monsterManager.addMount(horse);
|
monsterManager.addMount(mount);
|
||||||
|
|
||||||
// Remove the hay
|
// Remove the hay
|
||||||
inv.setItem(hay, null);
|
inv.setItem(hay, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private EntityType horseTypeFromAmount(int amount) {
|
||||||
|
switch (amount % 8) {
|
||||||
|
case 2: return EntityType.DONKEY;
|
||||||
|
case 3: return EntityType.MULE;
|
||||||
|
case 4: return EntityType.SKELETON_HORSE;
|
||||||
|
case 5: return EntityType.ZOMBIE_HORSE;
|
||||||
|
case 6: return EntityType.LLAMA;
|
||||||
|
default: return EntityType.HORSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Material bardingFromAmount(int amount) {
|
||||||
|
switch ((amount >> 3) % 4) {
|
||||||
|
case 1: return Material.IRON_BARDING;
|
||||||
|
case 2: return Material.GOLD_BARDING;
|
||||||
|
case 3: return Material.DIAMOND_BARDING;
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void removePotionEffects(Player p) {
|
private void removePotionEffects(Player p) {
|
||||||
for (PotionEffect effect : p.getActivePotionEffects()) {
|
for (PotionEffect effect : p.getActivePotionEffects()) {
|
||||||
p.removePotionEffect(effect.getType());
|
p.removePotionEffect(effect.getType());
|
||||||
|
|||||||
Reference in New Issue
Block a user