Advertisement
Corosus

Untitled

May 24th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.96 KB | None | 0 0
  1. package combat.enhancer.item;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import scala.collection.mutable.HashMap;
  7.  
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.entity.EntityLiving;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.EnumToolMaterial;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.item.ItemSword;
  15. import net.minecraft.nbt.NBTTagCompound;
  16. import net.minecraft.util.AxisAlignedBB;
  17. import net.minecraft.util.DamageSource;
  18. import net.minecraft.util.Icon;
  19. import net.minecraft.world.World;
  20.  
  21.  
  22. public class VectorWeapon extends ItemSword {
  23.  
  24. //Client only fields
  25. //public boolean isSwinging = false;
  26. //public int swingTimeCur = 0;
  27. public int swingTimeMax = 10;
  28. public int swingTimeCooldown = 20;
  29.  
  30. //this is used server side, should be split up to each player otherwise potential data collisions
  31. public HashMap<Integer, Boolean> swingHitEntityIDs = new HashMap<Integer, Boolean>();
  32.  
  33. public VectorWeapon(int par1, EnumToolMaterial par2EnumToolMaterial) {
  34. super(par1, par2EnumToolMaterial);
  35. // TODO Auto-generated constructor stub
  36. }
  37.  
  38. @Override
  39. public Icon getIconFromDamage(int par1) {
  40. return Item.swordIron.getIconFromDamage(0);
  41. }
  42.  
  43. @Override
  44. public boolean hitEntity(ItemStack par1ItemStack, EntityLiving par2EntityLiving, EntityLiving par3EntityLiving)
  45. {
  46. //par1ItemStack.damageItem(1, par3EntityLiving);
  47. //par2EntityLiving.worldObj.playSoundAtEntity(par2EntityLiving, "zc.meleehit", 1.0F, 1.0F);
  48. //possibly not needed
  49. return false;
  50. }
  51.  
  52. @Override
  53. public int getDamageVsEntity(Entity par1Entity)
  54. {
  55. System.out.println("sdfsfsdfsdf");
  56. //this prevents the damage vanilla style
  57. return 0;
  58. }
  59.  
  60. @Override
  61. public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
  62. if (par1ItemStack.stackTagCompound == null) par1ItemStack.stackTagCompound = new NBTTagCompound();
  63.  
  64. if (par5) {
  65. if (!par2World.isRemote) {
  66. int serverSwingTime = par1ItemStack.stackTagCompound.getInteger("swingTimeCur");
  67.  
  68. if (serverSwingTime > 0) {
  69. serverSwingTime--;
  70. par1ItemStack.stackTagCompound.setInteger("swingTimeCur", serverSwingTime);
  71. if (serverSwingTime == 0) {
  72. //end of swing
  73. System.out.println("SWINGED");
  74. swingHitEntityIDs.clear();
  75. } else {
  76. System.out.println("SWINGING");
  77. updateSwing(par1ItemStack, par2World, par3Entity, serverSwingTime);
  78. }
  79. } else {
  80.  
  81. }
  82. }
  83. //System.out.println(par5);
  84. }
  85. }
  86.  
  87. @Override
  88. public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
  89. if (par1ItemStack.stackTagCompound == null) par1ItemStack.stackTagCompound = new NBTTagCompound();
  90.  
  91. int serverSwingTime = par1ItemStack.stackTagCompound.getInteger("swingTimeCur");
  92. if (serverSwingTime <= 0) {
  93. System.out.println("SWING");
  94.  
  95. //temp
  96. swingTimeMax = 10;
  97. swingTimeCooldown = 20;
  98.  
  99. par1ItemStack.stackTagCompound.setInteger("swingTimeCur", swingTimeMax);
  100. }
  101.  
  102. System.out.println(par2World.isRemote);
  103.  
  104. return par1ItemStack;
  105. }
  106.  
  107. public void updateSwing(ItemStack par1ItemStack, World par2World, Entity par3Entity, int swingTime) {
  108. //assume 0 = default right to left
  109. int gestureType = par1ItemStack.stackTagCompound.getInteger("gestureType");
  110.  
  111. double swingSizeDegrees = 60D;
  112. double swingCurDegrees = ((double)swingTime / (double)swingTimeMax) * swingSizeDegrees;
  113.  
  114. double adjAngle = 90D + ((swingSizeDegrees / 2) - swingCurDegrees);
  115.  
  116. System.out.println("adjAngle: " + adjAngle);
  117.  
  118. double swingMin = 0.5D;
  119. double swingRes = 0.5D;
  120. double swingReach = 1.5D;
  121.  
  122. for (double range = swingMin; range <= swingReach; range += swingRes) {
  123. //System.out.println("range: " + range);
  124. double dist = range;
  125.  
  126. Entity center = par3Entity;
  127.  
  128. double posX = (center.posX - Math.cos((-center.rotationYaw + adjAngle) * 0.01745329D) * dist);
  129. double posY = (center.posY/* - 0.3D - Math.sin((center.rotationPitch) / 180.0F * 3.1415927F) * dist*/);
  130. double posZ = (center.posZ + Math.sin((-center.rotationYaw + adjAngle) * 0.01745329D) * dist);
  131.  
  132. //System.out.println(posX + ", " + posY + ", " + posZ);
  133.  
  134. double aabbSize = 1.0D;
  135.  
  136. AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(posX, posY, posZ, posX, posY, posZ).expand(aabbSize, aabbSize, aabbSize);
  137.  
  138. List entities = par2World.getEntitiesWithinAABB(EntityLiving.class, aabb);
  139.  
  140. for (int i = 0; i < entities.size(); i++) {
  141. EntityLiving entL = (EntityLiving)entities.get(i);
  142. if (entL != null && !entL.isDead && entL != par3Entity && !swingHitEntityIDs.contains(entL.entityId)) {
  143. System.out.println("hit! " + entL);
  144. entL.attackEntityFrom(DamageSource.causeMobDamage((EntityLiving)par3Entity), 2);
  145. swingHitEntityIDs.put(entL.entityId, true);
  146. }
  147. }
  148. }
  149. }
  150.  
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement