Small bit of framework for Soul Breath items, plus testing with the "Scroll of Icarus". Crafting mechanic as well as refilling of its resource not implemented.

This commit is contained in:
WayofTime 2018-04-28 21:56:57 -04:00
parent 560d167765
commit eb6b8a3aa5
7 changed files with 174 additions and 58 deletions

View file

@ -1,10 +1,13 @@
package WayofTime.bloodmagic.potion;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.event.SacrificeKnifeUsedEvent;
import WayofTime.bloodmagic.core.RegistrarBloodMagic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.potion.PotionEffect;
@ -16,15 +19,20 @@ import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.List;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.core.RegistrarBloodMagic;
import WayofTime.bloodmagic.event.SacrificeKnifeUsedEvent;
@Mod.EventBusSubscriber(modid = BloodMagic.MODID)
public class PotionEventHandlers {
public class PotionEventHandlers
{
public static List<EntityPlayer> flightList = new ArrayList<EntityPlayer>();
@SubscribeEvent
public static void onLivingJumpEvent(LivingEvent.LivingJumpEvent event) {
if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.BOOST)) {
public static void onLivingJumpEvent(LivingEvent.LivingJumpEvent event)
{
if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.BOOST))
{
int i = event.getEntityLiving().getActivePotionEffect(RegistrarBloodMagic.BOOST).getAmplifier();
event.getEntityLiving().motionY += (0.1f) * (2 + i);
}
@ -35,7 +43,33 @@ public class PotionEventHandlers {
}
@SubscribeEvent
public static void onEntityUpdate(LivingEvent.LivingUpdateEvent event) {
public static void onEntityUpdate(LivingEvent.LivingUpdateEvent event)
{
if (event.getEntityLiving() instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.getEntityLiving();
if (!player.world.isRemote)
{
if (player.isPotionActive(RegistrarBloodMagic.FLIGHT))
{
if (!player.isSpectator() && !player.capabilities.allowFlying)
{
player.capabilities.allowFlying = true;
player.sendPlayerAbilities();
flightList.add(player);
}
} else
{
if (flightList.contains(player))
{
player.capabilities.allowFlying = false;
player.capabilities.isFlying = false;
player.sendPlayerAbilities();
flightList.remove(player);
}
}
}
}
// if (event.getEntityLiving().isPotionActive(ModPotions.boost))
// {
// int i = event.getEntityLiving().getActivePotionEffect(ModPotions.boost).getAmplifier();
@ -52,12 +86,14 @@ public class PotionEventHandlers {
// }
// }
if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.WHIRLWIND)) {
if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.WHIRLWIND))
{
int d0 = 3;
AxisAlignedBB axisAlignedBB = new AxisAlignedBB(event.getEntityLiving().posX - 0.5, event.getEntityLiving().posY - 0.5, event.getEntityLiving().posZ - 0.5, event.getEntityLiving().posX + 0.5, event.getEntityLiving().posY + 0.5, event.getEntityLiving().posZ + 0.5).expand(d0, d0, d0);
List<Entity> entityList = event.getEntityLiving().getEntityWorld().getEntitiesWithinAABB(Entity.class, axisAlignedBB);
for (Entity projectile : entityList) {
for (Entity projectile : entityList)
{
if (projectile == null)
continue;
if (!(projectile instanceof IProjectile))
@ -84,7 +120,8 @@ public class PotionEventHandlers {
if (angle < 3 * (Math.PI / 4))
continue; // angle is < 135 degrees
if (throwingEntity != null) {
if (throwingEntity != null)
{
delX = -projectile.posX + throwingEntity.posX;
delY = -projectile.posY + (throwingEntity.posY + throwingEntity.getEyeHeight());
delZ = -projectile.posZ + throwingEntity.posZ;
@ -104,26 +141,31 @@ public class PotionEventHandlers {
}
@SubscribeEvent
public static void onPlayerRespawn(PlayerEvent.Clone event) {
public static void onPlayerRespawn(PlayerEvent.Clone event)
{
if (event.isWasDeath())
event.getEntityPlayer().addPotionEffect(new PotionEffect(RegistrarBloodMagic.SOUL_FRAY, 400));
}
@SubscribeEvent
public static void onSacrificeKnifeUsed(SacrificeKnifeUsedEvent event) {
public static void onSacrificeKnifeUsed(SacrificeKnifeUsedEvent event)
{
if (event.player.isPotionActive(RegistrarBloodMagic.SOUL_FRAY))
event.lpAdded = (int) (event.lpAdded * 0.1D);
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public static void onPlayerDamageEvent(LivingAttackEvent event) {
public static void onPlayerDamageEvent(LivingAttackEvent event)
{
if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.WHIRLWIND) && event.isCancelable() && event.getSource().isProjectile())
event.setCanceled(true);
}
@SubscribeEvent
public static void onEndermanTeleportEvent(EnderTeleportEvent event) {
if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.PLANAR_BINDING) && event.isCancelable()) {
public static void onEndermanTeleportEvent(EnderTeleportEvent event)
{
if (event.getEntityLiving().isPotionActive(RegistrarBloodMagic.PLANAR_BINDING) && event.isCancelable())
{
event.setCanceled(true);
}
}