From 06f1cbcce9ac91cce912f468c3df25bd756f6c39 Mon Sep 17 00:00:00 2001 From: GotoLink Date: Sun, 16 Mar 2014 23:37:30 +0100 Subject: [PATCH] Fixed staves and orbs particles -Also fixed air stuff SMP crash --- common/MysticWorld/Items/ItemOrbAir.java | 31 ++++--- common/MysticWorld/Items/ItemOrbEarth.java | 2 +- common/MysticWorld/Items/ItemOrbEnergy.java | 8 +- common/MysticWorld/Items/ItemOrbFire.java | 8 +- common/MysticWorld/Items/ItemOrbWater.java | 5 +- common/MysticWorld/Items/ItemStaffAir.java | 85 ++++++++------------ common/MysticWorld/Items/ItemStaffEarth.java | 5 +- common/MysticWorld/Items/ItemStaffEnegy.java | 7 +- common/MysticWorld/Items/ItemStaffFire.java | 7 +- common/MysticWorld/Items/ItemStaffWater.java | 5 +- 10 files changed, 66 insertions(+), 97 deletions(-) diff --git a/common/MysticWorld/Items/ItemOrbAir.java b/common/MysticWorld/Items/ItemOrbAir.java index 99ac3e1..9eb75d7 100644 --- a/common/MysticWorld/Items/ItemOrbAir.java +++ b/common/MysticWorld/Items/ItemOrbAir.java @@ -8,8 +8,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.MathHelper; import net.minecraft.world.World; -import org.lwjgl.input.Mouse; - public class ItemOrbAir extends ItemOrb { public ItemOrbAir() { super(); @@ -25,6 +23,18 @@ public class ItemOrbAir extends ItemOrb { return itemStack; } + @Override + public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityPlayer player, int par4) { + 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 + (itemStack.stackTagCompound.getInteger("chargeTime")) * (2.5D * (1.0D / itemStack.stackTagCompound.getInteger("maxChargeTime"))), 0.0D); + itemStack.damageItem(1, player); + } + } + resetData(itemStack); + } + @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) { if (itemStack.stackTagCompound == null) @@ -36,16 +46,7 @@ public class ItemOrbAir extends ItemOrb { if (par5) { player.fallDistance = 0.0F; chargeEffect(itemStack, world, player); - if (!Mouse.isButtonDown(1)) { - 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 + (itemStack.stackTagCompound.getInteger("chargeTime")) * (2.5D * (1.0D / itemStack.stackTagCompound.getInteger("maxChargeTime"))), 0.0D); - itemStack.damageItem(1, player); - } - } - resetData(itemStack); - } else { + if (player.isUsingItem()) { if (itemStack.stackTagCompound.getBoolean("charging")) { incrementData(itemStack); } @@ -71,8 +72,7 @@ public class ItemOrbAir extends ItemOrb { 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); + MysticWorld.proxy.airFeetFX(world, particleX, player.posY, particleZ, 1.0f, 15); } private void incrementData(ItemStack itemStack) { @@ -93,7 +93,6 @@ public class ItemOrbAir extends ItemOrb { double particleY = player.posY; double particleZ = player.posZ + (MathHelper.sin(itemStack.stackTagCompound.getFloat("angle"))) * itemStack.stackTagCompound.getDouble("radius"); float particleScale = ((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); + MysticWorld.proxy.airFeetFX(world, particleX, particleY, particleZ, 1.0f + particleScale, 15); } } diff --git a/common/MysticWorld/Items/ItemOrbEarth.java b/common/MysticWorld/Items/ItemOrbEarth.java index e1ad6de..c0ac44c 100644 --- a/common/MysticWorld/Items/ItemOrbEarth.java +++ b/common/MysticWorld/Items/ItemOrbEarth.java @@ -30,7 +30,7 @@ public class ItemOrbEarth extends ItemOrb { @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) { EntityPlayer player = (EntityPlayer) entity; - if (!world.isRemote && par5) { + if (par5) { MysticWorld.proxy.earthFX(world, (player.posX - 0.5D) + rand.nextDouble(), player.posY, (player.posZ - 0.5D) + rand.nextDouble(), 1.0F); } } diff --git a/common/MysticWorld/Items/ItemOrbEnergy.java b/common/MysticWorld/Items/ItemOrbEnergy.java index 81ef707..9202fa3 100644 --- a/common/MysticWorld/Items/ItemOrbEnergy.java +++ b/common/MysticWorld/Items/ItemOrbEnergy.java @@ -51,11 +51,9 @@ public class ItemOrbEnergy extends ItemOrb { @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) { - EntityPlayer player = (EntityPlayer) entity; - ItemStack currentItem = player.inventory.getCurrentItem(); - if (!world.isRemote && par5) { - player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 20, 2)); - MysticWorld.proxy.energyFX(world, (player.posX - 0.5D) + rand.nextDouble(), player.posY, (player.posZ - 0.5D) + rand.nextDouble(), 1.0F); + if (entity instanceof EntityPlayer && par5) { + ((EntityPlayer)entity).addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 20, 2)); + MysticWorld.proxy.energyFX(world, (entity.posX - 0.5D) + rand.nextDouble(), entity.posY, (entity.posZ - 0.5D) + rand.nextDouble(), 1.0F); } } } diff --git a/common/MysticWorld/Items/ItemOrbFire.java b/common/MysticWorld/Items/ItemOrbFire.java index 8b1d909..3c155f2 100644 --- a/common/MysticWorld/Items/ItemOrbFire.java +++ b/common/MysticWorld/Items/ItemOrbFire.java @@ -1,7 +1,6 @@ package mysticworld.items; import mysticworld.MysticWorld; -import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; @@ -67,10 +66,9 @@ public class ItemOrbFire extends ItemOrb { @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) { - EntityPlayer player = (EntityPlayer) entity; - if (!world.isRemote && par5) { - player.addPotionEffect(new PotionEffect(Potion.fireResistance.getId(), 20, 0)); - MysticWorld.proxy.fireFX(world, (player.posX - 0.5D) + rand.nextDouble(), player.posY, (player.posZ - 0.5D) + rand.nextDouble(), 1.0F); + if (entity instanceof EntityPlayer && par5) { + ((EntityPlayer)entity).addPotionEffect(new PotionEffect(Potion.fireResistance.getId(), 20, 0)); + MysticWorld.proxy.fireFX(world, (entity.posX - 0.5D) + rand.nextDouble(), entity.posY, (entity.posZ - 0.5D) + rand.nextDouble(), 1.0F); } } } diff --git a/common/MysticWorld/Items/ItemOrbWater.java b/common/MysticWorld/Items/ItemOrbWater.java index cb18d8f..368054a 100644 --- a/common/MysticWorld/Items/ItemOrbWater.java +++ b/common/MysticWorld/Items/ItemOrbWater.java @@ -74,9 +74,8 @@ public class ItemOrbWater extends ItemOrb { @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) { - EntityPlayer player = (EntityPlayer) entity; - if (!world.isRemote && par5) { - MysticWorld.proxy.waterFX(world, (player.posX - 0.5D) + rand.nextDouble(), player.posY, (player.posZ - 0.5D) + rand.nextDouble(), 1.0F); + if (par5) { + MysticWorld.proxy.waterFX(world, (entity.posX - 0.5D) + rand.nextDouble(), entity.posY, (entity.posZ - 0.5D) + rand.nextDouble(), 1.0F); } } } diff --git a/common/MysticWorld/Items/ItemStaffAir.java b/common/MysticWorld/Items/ItemStaffAir.java index e8376fa..f828809 100644 --- a/common/MysticWorld/Items/ItemStaffAir.java +++ b/common/MysticWorld/Items/ItemStaffAir.java @@ -1,15 +1,13 @@ package mysticworld.items; +import cpw.mods.fml.common.ObfuscationReflectionHelper; import mysticworld.MysticWorld; import mysticworld.entity.EntityChargeAir; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -import org.lwjgl.input.Mouse; - public class ItemStaffAir extends ItemStaff { public ItemStaffAir() { super(); @@ -17,64 +15,45 @@ public class ItemStaffAir extends ItemStaff { @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { - if (itemStack.stackTagCompound == null) - itemStack.setTagCompound(new NBTTagCompound()); - if (!itemStack.stackTagCompound.getBoolean("charging")) { - itemStack.stackTagCompound.setBoolean("charging", true); - } + player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack)); return itemStack; } + @Override + public int getMaxItemUseDuration(ItemStack itemStack){ + return 3*20; + } + + @Override + public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityPlayer player, int time) { + int charge = getMaxItemUseDuration(itemStack)-time; + if (charge > 0) { + if (!world.isRemote) { + world.playAuxSFXAtEntity(null, 1009, (int) player.posX, (int) player.posY, (int) player.posZ, 0); + world.spawnEntityInWorld(new EntityChargeAir(world, player, 1.0f + charge * (5.0f * (1 / (float) getMaxItemUseDuration(itemStack))), charge * (2.5D * (1.0D / getMaxItemUseDuration(itemStack))))); + itemStack.damageItem(1, player); + } + } + } + @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.stackTagCompound.setInteger("maxChargeTime", 3 * 20); - if (currentItem != null) { - if (currentItem.getItem() == itemStack.getItem()) { - player.fallDistance = 0.0F; - chargeEffect(itemStack, world, player); - if (!Mouse.isButtonDown(1)) { - if (itemStack.stackTagCompound.getInteger("chargeTime") > 0) { - if (!world.isRemote) { - world.playAuxSFXAtEntity(null, 1009, (int) player.posX, (int) player.posY, (int) player.posZ, 0); - world.spawnEntityInWorld(new EntityChargeAir(world, player, 1.0f + ((itemStack.stackTagCompound.getInteger("chargeTime")) * (5.0f * (1 / (float) itemStack.stackTagCompound - .getInteger("maxChargeTime")))), (itemStack.stackTagCompound.getInteger("chargeTime")) * (2.5D * (1.0D / itemStack.stackTagCompound.getInteger("maxChargeTime"))))); - itemStack.damageItem(1, player); - } - } - resetData(itemStack); - } else { - if (itemStack.stackTagCompound.getBoolean("charging") == true) { - incrementData(itemStack); - } - } - } - } else { - resetData(itemStack); - } - if (itemStack.stackTagCompound.getInteger("chargeTime") > itemStack.stackTagCompound.getInteger("maxChargeTime")) { - itemStack.stackTagCompound.setInteger("chargeTime", itemStack.stackTagCompound.getInteger("maxChargeTime")); + public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean current) { + if (current) { + entity.fallDistance = 0.0F; + if(entity instanceof EntityPlayer){ + if(((EntityPlayer) entity).isUsingItem()){ + int charge = ObfuscationReflectionHelper.getPrivateValue(EntityPlayer.class,(EntityPlayer) entity, "itemInUseCount", "field_71072_f"); + chargeEffect(itemStack, world, entity, getMaxItemUseDuration(itemStack) - charge); + } + } } } - private void chargeEffect(ItemStack itemStack, World world, EntityPlayer player) { + private void chargeEffect(ItemStack itemStack, World world, Entity player, int charge) { double particleX = (player.posX - 0.5D) + rand.nextDouble(); - double particleY = player.posY + (player.height / itemStack.stackTagCompound.getInteger("maxChargeTime") * itemStack.stackTagCompound.getInteger("chargeTime")); + double particleY = player.posY + (charge * player.height / getMaxItemUseDuration(itemStack)); double particleZ = (player.posZ - 0.5D) + rand.nextDouble(); - float particleScale = ((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 incrementData(ItemStack itemStack) { - itemStack.stackTagCompound.setInteger("chargeTime", itemStack.stackTagCompound.getInteger("chargeTime") + 1); - } - - private void resetData(ItemStack itemStack) { - itemStack.stackTagCompound.setInteger("chargeTime", 0); - itemStack.stackTagCompound.setBoolean("charging", false); + float particleScale = charge * (5.0f * (1 / (float) getMaxItemUseDuration(itemStack))); + MysticWorld.proxy.airFeetFX(world, particleX, particleY, particleZ, 1.0f + particleScale, 15); } } diff --git a/common/MysticWorld/Items/ItemStaffEarth.java b/common/MysticWorld/Items/ItemStaffEarth.java index 729a810..850736c 100644 --- a/common/MysticWorld/Items/ItemStaffEarth.java +++ b/common/MysticWorld/Items/ItemStaffEarth.java @@ -53,9 +53,8 @@ public class ItemStaffEarth extends ItemStaff { @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) { - EntityPlayer player = (EntityPlayer) entity; - if (!world.isRemote && par5) { - MysticWorld.proxy.earthFX(world, (player.posX - 0.5D) + rand.nextDouble(), player.posY, (player.posZ - 0.5D) + rand.nextDouble(), 1.0F); + if (par5) { + MysticWorld.proxy.earthFX(world, (entity.posX - 0.5D) + rand.nextDouble(), entity.posY, (entity.posZ - 0.5D) + rand.nextDouble(), 1.0F); } } diff --git a/common/MysticWorld/Items/ItemStaffEnegy.java b/common/MysticWorld/Items/ItemStaffEnegy.java index 706be06..03fad1d 100644 --- a/common/MysticWorld/Items/ItemStaffEnegy.java +++ b/common/MysticWorld/Items/ItemStaffEnegy.java @@ -77,10 +77,9 @@ public class ItemStaffEnegy extends ItemStaff { @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) { - EntityPlayer player = (EntityPlayer) entity; - if (!world.isRemote && par5) { - player.addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 20, 2)); - MysticWorld.proxy.energyFX(world, (player.posX - 0.5D) + rand.nextDouble(), player.posY, (player.posZ - 0.5D) + rand.nextDouble(), 1.0F); + if (entity instanceof EntityPlayer && par5) { + ((EntityPlayer)entity).addPotionEffect(new PotionEffect(Potion.moveSpeed.getId(), 20, 2)); + MysticWorld.proxy.energyFX(world, (entity.posX - 0.5D) + rand.nextDouble(), entity.posY, (entity.posZ - 0.5D) + rand.nextDouble(), 1.0F); } } } diff --git a/common/MysticWorld/Items/ItemStaffFire.java b/common/MysticWorld/Items/ItemStaffFire.java index 4c89a2b..5fb97be 100644 --- a/common/MysticWorld/Items/ItemStaffFire.java +++ b/common/MysticWorld/Items/ItemStaffFire.java @@ -81,10 +81,9 @@ public class ItemStaffFire extends ItemStaff { @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) { - EntityPlayer player = (EntityPlayer) entity; - if (!world.isRemote && par5) { - player.addPotionEffect(new PotionEffect(Potion.fireResistance.getId(), 20, 0)); - MysticWorld.proxy.fireFX(world, (player.posX - 0.5D) + rand.nextDouble(), player.posY, (player.posZ - 0.5D) + rand.nextDouble(), 1.0F); + if (entity instanceof EntityPlayer && par5) { + ((EntityPlayer)entity).addPotionEffect(new PotionEffect(Potion.fireResistance.getId(), 20, 0)); + MysticWorld.proxy.fireFX(world, (entity.posX - 0.5D) + rand.nextDouble(), entity.posY, (entity.posZ - 0.5D) + rand.nextDouble(), 1.0F); } } } diff --git a/common/MysticWorld/Items/ItemStaffWater.java b/common/MysticWorld/Items/ItemStaffWater.java index 2c68cd5..6d665e4 100644 --- a/common/MysticWorld/Items/ItemStaffWater.java +++ b/common/MysticWorld/Items/ItemStaffWater.java @@ -87,9 +87,8 @@ public class ItemStaffWater extends ItemStaff { @Override public void onUpdate(ItemStack itemStack, World world, Entity entity, int par4, boolean par5) { - EntityPlayer player = (EntityPlayer) entity; - if (!world.isRemote && par5) { - MysticWorld.proxy.waterFX(world, (player.posX - 0.5D) + rand.nextDouble(), player.posY, (player.posZ - 0.5D) + rand.nextDouble(), 1.0F); + if (par5) { + MysticWorld.proxy.waterFX(world, (entity.posX - 0.5D) + rand.nextDouble(), entity.posY, (entity.posZ - 0.5D) + rand.nextDouble(), 1.0F); } } } \ No newline at end of file