Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1.  
  2. import net.minecraft.entity.EntityLivingBase;
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.entity.projectile.EntityThrowable;
  5. import net.minecraft.item.EnumAction;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.util.DamageSource;
  8. import net.minecraft.util.MathHelper;
  9. import net.minecraft.util.MovingObjectPosition;
  10. import net.minecraft.world.World;
  11. import net.minecraftforge.common.ForgeDirection;
  12. import thaumcraft.client.codechicken.core.vec.Vector3;
  13. import thaumcraft.client.fx.FXSparkle;
  14. import vazkii.tinkerer.common.ThaumicTinkerer;
  15. import cpw.mods.fml.common.registry.EntityRegistry;
  16. import cpw.mods.fml.common.registry.LanguageRegistry;
  17.  
  18. public class ItemShadowStaff extends ItemMod {
  19.  
  20. public ItemShadowStaff(int par1) {
  21. super(par1);
  22. setMaxStackSize(1);
  23.  
  24. EntityRegistry.registerModEntity(Beam.class, "ShadowbeamStaffBeam", 0, ThaumicTinkerer.instance, 0, 0, false);
  25.  
  26. // Sloppy registry, couldn't bother to actually write a lang
  27. setUnlocalizedName("ttinkerer:shadowStaff");
  28. LanguageRegistry.addName(this, "Shadowbeam Staff");
  29.  
  30. // Item Texture download: http://puu.sh/6ehlP.png
  31. }
  32.  
  33. @Override
  34. public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
  35. par3EntityPlayer.setItemInUse(par1ItemStack, getMaxItemUseDuration(par1ItemStack));
  36. par3EntityPlayer.worldObj.playSoundAtEntity(par3EntityPlayer, "thaumcraft:brain", 1F, 1F);
  37.  
  38. return par1ItemStack;
  39. }
  40.  
  41. @Override
  42. public void onUsingItemTick(ItemStack stack, EntityPlayer player, int count) {
  43. if(!player.worldObj.isRemote) {
  44. Beam beam = new Beam(player.worldObj, player);
  45. beam.updateUntilDead();
  46. }
  47. }
  48.  
  49. @Override
  50. public int getMaxItemUseDuration(ItemStack par1ItemStack) {
  51. return 72000;
  52. }
  53.  
  54. @Override
  55. public EnumAction getItemUseAction(ItemStack par1ItemStack) {
  56. return EnumAction.bow;
  57. }
  58.  
  59. @Override
  60. public boolean isFull3D() {
  61. return true;
  62. }
  63.  
  64. @Override
  65. public boolean shouldRotateAroundWhenRendering() {
  66. return true;
  67. }
  68.  
  69. public static class Particle extends FXSparkle {
  70.  
  71. public Particle(World world, double d, double d1, double d2, float f, int type, int m) {
  72. super(world, d, d1, d2, f, type, m);
  73. noClip = true;
  74. }
  75.  
  76. @Override
  77. public void onUpdate() {
  78. super.onUpdate();
  79. if(particleAge > 1)
  80. setDead();
  81. }
  82. }
  83.  
  84. public static class Beam extends EntityThrowable {
  85. Vector3 movementVector;
  86. final int maxTicks = 1000;
  87.  
  88. public Beam(World par1World, EntityLivingBase par2EntityLivingBase) {
  89. super(par1World, par2EntityLivingBase);
  90.  
  91. setVelocity(motionX / 10, motionY / 10, motionZ / 10);
  92. movementVector = new Vector3(motionX, motionY, motionZ);
  93. }
  94.  
  95. public void setThrowableHeading(double par1, double par3, double par5, float par7, float par8)
  96. {
  97. super.setThrowableHeading(par1, par3, par5, par7, par8);
  98. float f2 = MathHelper.sqrt_double(par1 * par1 + par3 * par3 + par5 * par5);
  99. par1 /= (double)f2;
  100. par3 /= (double)f2;
  101. par5 /= (double)f2;
  102. par1 += 0.007499999832361937D * (double)par8;
  103. par3 += 0.007499999832361937D * (double)par8;
  104. par5 += 0.007499999832361937D * (double)par8;
  105. par1 *= (double)par7;
  106. par3 *= (double)par7;
  107. par5 *= (double)par7;
  108. this.motionX = par1;
  109. this.motionY = par3;
  110. this.motionZ = par5;
  111. }
  112.  
  113. @Override
  114. protected void onImpact(MovingObjectPosition movingobjectposition) {
  115. if(movingobjectposition == null)
  116. return;
  117.  
  118. if(movingobjectposition.entityHit != null) {
  119. if(movingobjectposition.entityHit != getThrower() && getThrower() instanceof EntityPlayer && !movingobjectposition.entityHit.worldObj.isRemote)
  120. movingobjectposition.entityHit.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) getThrower()), 5);
  121. return;
  122. }
  123.  
  124. Vector3 movementVec = new Vector3(motionX, motionY, motionZ);
  125. ForgeDirection dir = ForgeDirection.getOrientation(movingobjectposition.sideHit);
  126. Vector3 normalVector = new Vector3(dir.offsetX, dir.offsetY, dir.offsetZ).normalize();
  127.  
  128. movementVector = normalVector.multiply(-2 * movementVec.dotProduct(normalVector)).add(movementVec);
  129.  
  130. motionX = movementVector.x;
  131. motionY = movementVector.y;
  132. motionZ = movementVector.z;
  133. }
  134.  
  135. @Override
  136. public void onUpdate() {
  137. motionX = movementVector.x;
  138. motionY = movementVector.y;
  139. motionZ = movementVector.z;
  140.  
  141. super.onUpdate();
  142.  
  143. ThaumicTinkerer.proxy.shadowSparkle(worldObj, (float) posX, (float) posY, (float) posZ, 6);
  144. /**
  145. * ItemShadowStaff.Particle particle = new ItemShadowStaff.Particle(world, x, y, z, 1.5F, 0, size);
  146. * ClientHelper.minecraft().effectRenderer.addEffect(particle);
  147. */
  148.  
  149. ++ticksExisted;
  150. if(ticksExisted >= maxTicks)
  151. setDead();
  152. }
  153.  
  154. public void updateUntilDead() {
  155. while(!isDead)
  156. onUpdate();
  157. }
  158.  
  159. @Override
  160. protected float getGravityVelocity() {
  161. return 0F;
  162. }
  163. }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement