From 7d7a8f0b7ec68cc525a1df0a14f195a4c6c860ab Mon Sep 17 00:00:00 2001 From: allstar69 Date: Wed, 24 Jul 2013 10:06:07 -0700 Subject: [PATCH] Added effects to air orb. --- common/MysticWorld/Items/ItemOrbAir.java | 116 ++++++++++++++++++--- common/MysticWorld/Items/ItemStaffAir.java | 89 +++++++--------- 2 files changed, 138 insertions(+), 67 deletions(-) diff --git a/common/MysticWorld/Items/ItemOrbAir.java b/common/MysticWorld/Items/ItemOrbAir.java index 7ce463a..e9eaf66 100644 --- a/common/MysticWorld/Items/ItemOrbAir.java +++ b/common/MysticWorld/Items/ItemOrbAir.java @@ -2,6 +2,9 @@ package MysticWorld.Items; import java.util.Random; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; + import MysticWorld.MysticWorld; import MysticWorld.Entity.EntityChargeAir; import net.minecraft.client.renderer.texture.IconRegister; @@ -9,6 +12,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.world.World; @@ -22,33 +26,117 @@ public class ItemOrbAir extends ItemOrb @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) { + if (itemStack.stackTagCompound == null) + itemStack.setTagCompound(new NBTTagCompound()); + EntityPlayer player = (EntityPlayer)entity; - ItemStack currentItem = player.inventory.getCurrentItem(); + ItemStack currentItem = player.inventory.getCurrentItem(); - if (!world.isRemote) + itemStack.stackTagCompound.setInteger("maxChargeTime", 5 * 20); + + if (currentItem != null) { - if (currentItem != null) + if (currentItem.itemID == itemStack.itemID) { - if (currentItem.itemID == itemStack.itemID) + player.fallDistance = 0.0F; + + chargeEffect(itemStack, world, player); + + if (!Mouse.isButtonDown(1)) { - player.fallDistance = 0.0F; - MysticWorld.proxy.airFeetFX(world, (player.posX - 0.5D) + rand.nextDouble(), player.posY, (player.posZ - 0.5D) + rand.nextDouble(), 1.0F, 15); + if (itemStack.stackTagCompound.getInteger("chargeTime") > 0) + { + if (player.onGround) + { + world.playSoundEffect(player.posX, player.posY, player.posZ, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F); + player.setVelocity(0.0D, 1.0D + (float)(itemStack.stackTagCompound.getInteger("chargeTime")) * (2.5D * (1.0D / (double)itemStack.stackTagCompound.getInteger("maxChargeTime"))), 0.0D); + + itemStack.damageItem(1, player); + } + } + + resetData(itemStack); } - } + else + { + if (itemStack.stackTagCompound.getBoolean("charging") == true) + { + incrementData(itemStack); + } + + spiralEffect(itemStack, world, player); + } + } + } + else + { + resetData(itemStack); + itemStack.stackTagCompound.setFloat("angle", 0); + itemStack.stackTagCompound.setDouble("radius", 0); + } + + if (itemStack.stackTagCompound.getInteger("chargeTime") > itemStack.stackTagCompound.getInteger("maxChargeTime")) + { + itemStack.stackTagCompound.setInteger("chargeTime", itemStack.stackTagCompound.getInteger("maxChargeTime")); + } + + if (itemStack.stackTagCompound.getDouble("radius") > 2.5D) + { + itemStack.stackTagCompound.setDouble("radius", 2.5D); + } + + if (itemStack.stackTagCompound.getFloat("angle") > 6.0f) + { + itemStack.stackTagCompound.setFloat("angle", 0.0f); } } @Override - public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer) - { - if (entityPlayer.onGround) + public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) + { + if (itemStack.stackTagCompound == null) + itemStack.setTagCompound(new NBTTagCompound()); + + if (itemStack.stackTagCompound.getBoolean("charging") == false) { - world.playSoundEffect(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F); - itemStack.damageItem(1, entityPlayer); - entityPlayer.addVelocity(0, 2.5, 0); + itemStack.stackTagCompound.setBoolean("charging", true); } - return itemStack; + return itemStack; } + private void spiralEffect(ItemStack itemStack, World world, EntityPlayer player) + { + double particleX = player.posX + (double)(MathHelper.cos(itemStack.stackTagCompound.getFloat("angle"))) * itemStack.stackTagCompound.getDouble("radius"); + double particleY = player.posY; + double particleZ = player.posZ + (double)(MathHelper.sin(itemStack.stackTagCompound.getFloat("angle"))) * itemStack.stackTagCompound.getDouble("radius"); + float particleScale = ((float)(itemStack.stackTagCompound.getInteger("chargeTime")) * (5.0f * (1 / (float)itemStack.stackTagCompound.getInteger("maxChargeTime")))); + + if (!world.isRemote) + MysticWorld.proxy.airFeetFX(world, particleX, particleY, particleZ, 1.0f + particleScale, 15); + } + + private void chargeEffect(ItemStack itemStack, World world, EntityPlayer player) + { + double particleX = (player.posX - 0.5D) + rand.nextDouble(); + double particleZ = (player.posZ - 0.5D) + rand.nextDouble(); + + if (!world.isRemote) + MysticWorld.proxy.airFeetFX(world, particleX, player.posY, particleZ, 1.0f, 15); + } + + private void resetData(ItemStack itemStack) + { + itemStack.stackTagCompound.setInteger("chargeTime", 0); + itemStack.stackTagCompound.setBoolean("charging", false); + itemStack.stackTagCompound.setFloat("angle", 0); + itemStack.stackTagCompound.setDouble("radius", 0); + } + + private void incrementData(ItemStack itemStack) + { + itemStack.stackTagCompound.setInteger("chargeTime", itemStack.stackTagCompound.getInteger("chargeTime") + 1); + itemStack.stackTagCompound.setFloat("angle", itemStack.stackTagCompound.getFloat("angle") + 0.2f); + itemStack.stackTagCompound.setDouble("radius", (double)itemStack.stackTagCompound.getInteger("chargeTime") * 0.025D); + } } diff --git a/common/MysticWorld/Items/ItemStaffAir.java b/common/MysticWorld/Items/ItemStaffAir.java index d683ad7..f545b41 100644 --- a/common/MysticWorld/Items/ItemStaffAir.java +++ b/common/MysticWorld/Items/ItemStaffAir.java @@ -36,78 +36,42 @@ public class ItemStaffAir extends ItemStaff { if (currentItem.itemID == itemStack.itemID) { player.fallDistance = 0.0F; - - if (!world.isRemote) - MysticWorld.proxy.airFeetFX(world, (player.posX - 0.5D) + rand.nextDouble(), player.posY + (player.height/itemStack.stackTagCompound.getInteger("maxChargeTime") * itemStack.stackTagCompound.getInteger("chargeTime")), (player.posZ - 0.5D) + rand.nextDouble(), 1.0f + ((float)(itemStack.stackTagCompound.getInteger("chargeTime")) * (5.0f * (1 / (float)itemStack.stackTagCompound.getInteger("maxChargeTime")))), 15); + + chargeEffect(itemStack, world, player); if (!Mouse.isButtonDown(1)) { if (itemStack.stackTagCompound.getInteger("chargeTime") > 0) - { - if (!(Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))) - { - if (!world.isRemote) - { - world.playAuxSFXAtEntity((EntityPlayer)null, 1009, (int)player.posX, (int)player.posY, (int)player.posZ, 0); - world.spawnEntityInWorld(new EntityChargeAir(world, player, 1.0f + ((float)(itemStack.stackTagCompound.getInteger("chargeTime")) * (5.0f * (1 / (float)itemStack.stackTagCompound.getInteger("maxChargeTime")))), (float)(itemStack.stackTagCompound.getInteger("chargeTime")) * (2.5D * (1.0D / (double)itemStack.stackTagCompound.getInteger("maxChargeTime"))))); - - itemStack.damageItem(1, player); - } - } - else + { + if (!world.isRemote) { - if (player.onGround) - { - world.playSoundEffect(player.posX, player.posY, player.posZ, "fire.ignite", 1.0F, itemRand.nextFloat() * 0.4F + 0.8F); - itemStack.damageItem(1, player); - player.setVelocity(0.0D, 1.0D + (float)(itemStack.stackTagCompound.getInteger("chargeTime")) * (2.5D * (1.0D / (double)itemStack.stackTagCompound.getInteger("maxChargeTime"))), 0.0D); - } + world.playAuxSFXAtEntity((EntityPlayer)null, 1009, (int)player.posX, (int)player.posY, (int)player.posZ, 0); + world.spawnEntityInWorld(new EntityChargeAir(world, player, 1.0f + ((float)(itemStack.stackTagCompound.getInteger("chargeTime")) * (5.0f * (1 / (float)itemStack.stackTagCompound.getInteger("maxChargeTime")))), (float)(itemStack.stackTagCompound.getInteger("chargeTime")) * (2.5D * (1.0D / (double)itemStack.stackTagCompound.getInteger("maxChargeTime"))))); + + itemStack.damageItem(1, player); } } - - itemStack.stackTagCompound.setInteger("chargeTime", 0); - itemStack.stackTagCompound.setFloat("angle", 0); - itemStack.stackTagCompound.setDouble("radius", 0); - itemStack.stackTagCompound.setBoolean("charging", false); + + resetData(itemStack); } else { - if ((Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))) - { - if (!world.isRemote) - MysticWorld.proxy.airFeetFX(world, player.posX + MathHelper.cos(itemStack.stackTagCompound.getFloat("angle")) * itemStack.stackTagCompound.getDouble("radius"), player.posY, player.posZ + MathHelper.sin(itemStack.stackTagCompound.getFloat("angle")) * itemStack.stackTagCompound.getDouble("radius"), 1.0f + ((float)(itemStack.stackTagCompound.getInteger("chargeTime")) * (5.0f * (1 / (float)itemStack.stackTagCompound.getInteger("maxChargeTime")))), 45); - } - if (itemStack.stackTagCompound.getBoolean("charging") == true) { - itemStack.stackTagCompound.setInteger("chargeTime", itemStack.stackTagCompound.getInteger("chargeTime") + 1); - itemStack.stackTagCompound.setFloat("angle", itemStack.stackTagCompound.getFloat("angle") + 0.1f); - itemStack.stackTagCompound.setDouble("radius", itemStack.stackTagCompound.getDouble("radius") + 0.1D); + incrementData(itemStack); } } } - else - { - itemStack.stackTagCompound.setInteger("chargeTime", 0); - itemStack.stackTagCompound.setFloat("angle", 0); - itemStack.stackTagCompound.setDouble("radius", 0); - } + } + else + { + resetData(itemStack); } if (itemStack.stackTagCompound.getInteger("chargeTime") > itemStack.stackTagCompound.getInteger("maxChargeTime")) { itemStack.stackTagCompound.setInteger("chargeTime", itemStack.stackTagCompound.getInteger("maxChargeTime")); } - - if (itemStack.stackTagCompound.getDouble("radius") > 7.0D) - { - itemStack.stackTagCompound.setDouble("radius", 7.0D); - } - - if (itemStack.stackTagCompound.getFloat("angle") > 6.0f) - { - itemStack.stackTagCompound.setFloat("angle", 0.0f); - } } @Override @@ -115,8 +79,6 @@ public class ItemStaffAir extends ItemStaff { { if (itemStack.stackTagCompound == null) itemStack.setTagCompound(new NBTTagCompound()); - - itemStack.stackTagCompound.setDouble("radius", 2.0D); if (itemStack.stackTagCompound.getBoolean("charging") == false) { @@ -126,4 +88,25 @@ public class ItemStaffAir extends ItemStaff { return itemStack; } + private void chargeEffect(ItemStack itemStack, World world, EntityPlayer player) + { + double particleX = (player.posX - 0.5D) + rand.nextDouble(); + double particleY = player.posY + (player.height/itemStack.stackTagCompound.getInteger("maxChargeTime") * itemStack.stackTagCompound.getInteger("chargeTime")); + double particleZ = (player.posZ - 0.5D) + rand.nextDouble(); + float particleScale = ((float)(itemStack.stackTagCompound.getInteger("chargeTime")) * (5.0f * (1 / (float)itemStack.stackTagCompound.getInteger("maxChargeTime")))); + + if (!world.isRemote) + MysticWorld.proxy.airFeetFX(world, particleX, particleY, particleZ, 1.0f + particleScale, 15); + } + + private void resetData(ItemStack itemStack) + { + itemStack.stackTagCompound.setInteger("chargeTime", 0); + itemStack.stackTagCompound.setBoolean("charging", false); + } + + private void incrementData(ItemStack itemStack) + { + itemStack.stackTagCompound.setInteger("chargeTime", itemStack.stackTagCompound.getInteger("chargeTime") + 1); + } }