Advertisement
Cmonster910

TNT entity

Jun 23rd, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. package com.Cmonster.OreMod.entities;
  2.  
  3. import javax.annotation.Nullable;
  4.  
  5. import net.minecraft.entity.Entity;
  6. import net.minecraft.entity.EntityLivingBase;
  7. import net.minecraft.entity.MoverType;
  8. import net.minecraft.entity.item.EntityTNTPrimed;
  9. import net.minecraft.nbt.NBTTagCompound;
  10. import net.minecraft.network.datasync.DataParameter;
  11. import net.minecraft.network.datasync.DataSerializers;
  12. import net.minecraft.network.datasync.EntityDataManager;
  13. import net.minecraft.util.EnumParticleTypes;
  14. import net.minecraft.world.World;
  15.  
  16. public class EntityJohn_tnt extends Entity
  17. {
  18. private static final DataParameter<Integer> FUSE = EntityDataManager.<Integer>createKey(EntityJohn_tnt.class, DataSerializers.VARINT);
  19. @Nullable
  20. private EntityLivingBase tntPlacedBy;
  21. /** How long the fuse is */
  22. private int fuse;
  23.  
  24. public EntityJohn_tnt(World worldIn)
  25. {
  26. super(worldIn);
  27. this.fuse = 80;
  28. this.preventEntitySpawning = true;
  29. this.setSize(0.98F, 0.98F);
  30. }
  31.  
  32. public EntityJohn_tnt(World worldIn, double x, double y, double z, EntityLivingBase igniter)
  33. {
  34. this(worldIn);
  35. this.setPosition(x, y, z);
  36. float f = (float)(Math.random() * (Math.PI * 2D));
  37. this.motionX = (double)(-((float)Math.sin((double)f)) * 0.02F);
  38. this.motionY = 0.20000000298023224D;
  39. this.motionZ = (double)(-((float)Math.cos((double)f)) * 0.02F);
  40. this.setFuse(80);
  41. this.prevPosX = x;
  42. this.prevPosY = y;
  43. this.prevPosZ = z;
  44. this.tntPlacedBy = igniter;
  45. }
  46.  
  47. protected void entityInit()
  48. {
  49. this.dataManager.register(FUSE, Integer.valueOf(80));
  50. }
  51.  
  52. /**
  53. * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
  54. * prevent them from trampling crops
  55. */
  56. protected boolean canTriggerWalking()
  57. {
  58. return false;
  59. }
  60.  
  61. /**
  62. * Returns true if other Entities should be prevented from moving through this Entity.
  63. */
  64. public boolean canBeCollidedWith()
  65. {
  66. return !this.isDead;
  67. }
  68.  
  69. /**
  70. * Called to update the entity's position/logic.
  71. */
  72. public void onUpdate()
  73. {
  74. this.prevPosX = this.posX;
  75. this.prevPosY = this.posY;
  76. this.prevPosZ = this.posZ;
  77.  
  78. if (!this.hasNoGravity())
  79. {
  80. this.motionY -= 0.03999999910593033D;
  81. }
  82.  
  83. this.move(MoverType.SELF, this.motionX, this.motionY, this.motionZ);
  84. this.motionX *= 0.9800000190734863D;
  85. this.motionY *= 0.9800000190734863D;
  86. this.motionZ *= 0.9800000190734863D;
  87.  
  88. if (this.onGround)
  89. {
  90. this.motionX *= 0.699999988079071D;
  91. this.motionZ *= 0.699999988079071D;
  92. this.motionY *= -0.5D;
  93. }
  94.  
  95. --this.fuse;
  96.  
  97. if (this.fuse <= 0)
  98. {
  99. this.setDead();
  100.  
  101. if (!this.world.isRemote)
  102. {
  103. this.explode();
  104. }
  105. }
  106. else
  107. {
  108. this.handleWaterMovement();
  109. this.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
  110. }
  111. }
  112.  
  113. private void explode()
  114. {
  115. float f = 4.0F;
  116. this.world.createExplosion(this, this.posX, this.posY + (double)(this.height / 16.0F), this.posZ, 100.0F, true);
  117. }
  118.  
  119. /**
  120. * (abstract) Protected helper method to write subclass entity data to NBT.
  121. */
  122. protected void writeEntityToNBT(NBTTagCompound compound)
  123. {
  124. compound.setShort("Fuse", (short)this.getFuse());
  125. }
  126.  
  127. /**
  128. * (abstract) Protected helper method to read subclass entity data from NBT.
  129. */
  130. protected void readEntityFromNBT(NBTTagCompound compound)
  131. {
  132. this.setFuse(compound.getShort("Fuse"));
  133. }
  134.  
  135. /**
  136. * returns null or the entityliving it was placed or ignited by
  137. */
  138. @Nullable
  139. public EntityLivingBase getTntPlacedBy()
  140. {
  141. return this.tntPlacedBy;
  142. }
  143.  
  144. public float getEyeHeight()
  145. {
  146. return 0.0F;
  147. }
  148.  
  149. public void setFuse(int fuseIn)
  150. {
  151. this.dataManager.set(FUSE, Integer.valueOf(fuseIn));
  152. this.fuse = fuseIn;
  153. }
  154.  
  155. public void notifyDataManagerChange(DataParameter<?> key)
  156. {
  157. if (FUSE.equals(key))
  158. {
  159. this.fuse = this.getFuseDataManager();
  160. }
  161. }
  162.  
  163. /**
  164. * Gets the fuse from the data manager
  165. */
  166. public int getFuseDataManager()
  167. {
  168. return ((Integer)this.dataManager.get(FUSE)).intValue();
  169. }
  170.  
  171. public int getFuse()
  172. {
  173. return this.fuse;
  174. }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement