@SubtargetedModuleMethod.Inject(
module = PlethoraModules.KINETIC_S, target = EntityWitch.class, name = "shoot",
doc = "function(potency:number) -- Throw a potion in the direction the witch is looking"
)
@Nonnull
public static MethodResult shootWitch(@Nonnull final IUnbakedContext<IModuleContainer> unbaked, @Nonnull final Object[] args) throws LuaException {
final double potency = getReal(args, 0);
assertBetween(potency, 0.1, 1.0, "Potency out of range (%s).");
return unbaked.getCostHandler().await(Kinetic.shootCost * potency, MethodResult.nextTick(() -> {
IContext<IModuleContainer> context = unbaked.bake();
EntityWitch witch = context.getContext(ContextKeys.ORIGIN, EntityWitch.class);
if (witch.isDrinkingPotion()) throw new LuaException("Currently drinking a potion");
World world = witch.getEntityWorld();
Vec3d motion = witch.getLookVec();
PotionType potionType = WITCH_POTIONS[witch.getRNG().nextInt(WITCH_POTIONS.length)];
EntityPotion potion = new EntityPotion(world, witch, PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION), potionType));
potion.rotationPitch -= -20.0F;
potion.shoot(motion.x, 0.2 + potency * 1.4, motion.y, 0.75F, 8.0F);
world.playSound(null, witch.posX, witch.posY, witch.posZ, SoundEvents.ENTITY_WITCH_THROW, witch.getSoundCategory(), 1.0F, 0.8F + witch.getRNG().nextFloat() * 0.4F);
world.spawnEntity(potion);
return MethodResult.empty();
}));
}