XZOzerTY

Code for the Guns/grenades Minecraft [Forge]

Mar 24th, 2013
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.63 KB | None | 0 0
  1. package ****;
  2.  
  3. import java.io.File;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.BlockGrass;
  7. import net.minecraft.block.BlockPane;
  8. import net.minecraft.block.BlockWeb;
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.client.Minecraft;
  11. import net.minecraft.creativetab.CreativeTabs;
  12. import net.minecraft.entity.Entity;
  13. import net.minecraft.entity.projectile.EntityArrow;
  14. import net.minecraft.item.EnumArmorMaterial;
  15. import net.minecraft.item.EnumToolMaterial;
  16. import net.minecraft.item.Item;
  17. import net.minecraft.item.ItemAppleGold;
  18. import net.minecraft.item.ItemArmor;
  19. import net.minecraft.item.ItemBow;
  20. import net.minecraft.item.ItemCarrotOnAStick;
  21. import net.minecraft.item.ItemSaddle;
  22. import net.minecraft.item.ItemSnowball;
  23. import net.minecraft.item.ItemStack;
  24. import net.minecraft.item.ItemSword;
  25. import net.minecraft.potion.Potion;
  26. import net.minecraft.potion.PotionHealth;
  27. import net.minecraft.src.ModLoader;
  28. import net.minecraft.util.DamageSource;
  29. import net.minecraft.util.EntityDamageSourceIndirect;
  30. import net.minecraft.world.biome.BiomeGenBase;
  31. import net.minecraft.world.biome.BiomeGenForest;
  32. import net.minecraft.world.biome.BiomeGenPlains;
  33. import net.minecraftforge.client.MinecraftForgeClient;
  34. import net.minecraftforge.common.EnumHelper;
  35. import net.minecraftforge.common.MinecraftForge;
  36. import cpw.mods.fml.client.registry.RenderingRegistry;
  37. import cpw.mods.fml.common.Mod;
  38. import cpw.mods.fml.common.Mod.Init;
  39. import cpw.mods.fml.common.Mod.PostInit;
  40. import cpw.mods.fml.common.Mod.PreInit;
  41. import cpw.mods.fml.common.event.FMLInitializationEvent;
  42. import cpw.mods.fml.common.event.FMLPostInitializationEvent;
  43. import cpw.mods.fml.common.event.FMLPreInitializationEvent;
  44. import cpw.mods.fml.common.network.NetworkMod;
  45. import cpw.mods.fml.common.registry.EntityRegistry;
  46. import cpw.mods.fml.common.registry.GameRegistry;
  47. import cpw.mods.fml.common.registry.LanguageRegistry;
  48. import java.io.File;
  49. import java.util.Random;
  50.  
  51. import javax.sound.sampled.Clip;
  52.  
  53.  
  54.  
  55.  
  56. @Mod (modid = "****", name = "****", version = "****")
  57. @NetworkMod(
  58. clientSideRequired = true,
  59. serverSideRequired = true,
  60. versionBounds = "[1.5]")
  61. public class BaseXZ {
  62.  
  63.  
  64.  
  65.  
  66. //guns
  67. public static Itemdeserteagle = (new Itemdeserteagle(4899, 8, 10, 4599, 1, "/soundsXZ/deserteagleshoot.ogg", null).setItemName("deserteagle").setIconIndex(14).setCreativeTab(CreativeTabs.tabCombat).setFull3D());
  68.  
  69. public static Itemdeserteagleclip = new xzItems(4599).setMaxStackSize(1).setItemName("deserteagleclip").setIconIndex(16).setCreativeTab(CreativeTabs.tabCombat);
  70.  
  71. public static Itemgrenade = (new Itemgrenade(4020).setItemName("grenade").setIconIndex(20).setCreativeTab(CreativeTabs.tabCombat));
  72.  
  73.  
  74.  
  75. @PreInit
  76. public void Init(FMLPreInitializationEvent preEvent) {
  77.  
  78.  
  79. }
  80.  
  81.  
  82. @Init
  83. public void Init(FMLInitializationEvent event) {
  84.  
  85. LanguageRegistry.addName(deserteagle, "Desert Eagle");
  86. LanguageRegistry.addName(deserteagleclip, "Desert Eagle Clip");
  87.  
  88.  
  89.  
  90. RenderingRegistry.registerEntityRenderingHandler(Entitygrenade.class, new RenderGrenade(20));
  91.  
  92. EntityRegistry.registerModEntity(Entitygrenade.class, "Grenade", 4020, this, 8, 1, true);
  93.  
  94.  
  95. }
  96.  
  97.  
  98. @PostInit
  99. public void Init(FMLPostInitializationEvent event) {
  100.  
  101.  
  102. }
  103.  
  104. }
  105.  
  106.  
  107. -----------------------Itemdeserteagle----------------------------------------------------
  108.  
  109. package ****;
  110.  
  111. import net.minecraft.entity.player.EntityPlayer;
  112. import net.minecraft.item.Item;
  113. import net.minecraft.item.ItemStack;
  114. import net.minecraft.world.World;
  115.  
  116. public class Itemdeserteagle extends Item{
  117.  
  118. //These are all of our base variables for our gun
  119. private int damage; //Damage in half-hearts
  120. private int reloadtick; //The current value of our reloading timer
  121. private int reloadmax; //The value that the reloadtick variable needs to be in order for the gun to reload
  122. private int clipid; //The item id of our clip
  123. private int ammo; //The amount of ammo avaliable per clip (used in setting durability)
  124. private int firetick; //The current value of our shooting timer
  125. private int firemax; //The value that the firetick variable needs to be in order for the gun to fire
  126. //Fire delay is completely ignored when firemax is set to 0
  127. private String firesound; //The String that notch uses in his code to figure out what sound to play when we shoot our gun
  128. private String reloadsound; //Firesound but with reloading
  129.  
  130. //The parameters for our constructor are:
  131. //int i (the id), int damage (damage in half-hearts), int ammo (how much ammo per clip)
  132. //int clipid (the item id of the clip this gun uses), int firedelay (the value of firemax)
  133. //String firesound (the value of firesound), String reloadsound (the value of reloadsound)
  134. public Itemdeserteagle(int i, int damage, int ammo, int clipid, int firedelay, String firesound, String reloadsound){
  135.  
  136. super(i); //calls the Item.java constructor and passes in the item id for a parameter
  137. this.damage = 8; //sets the damage value
  138. firemax = 1; //sets the firemax value
  139. firetick = firemax; //sets the firetick value equal to firemax (so you don't need to wait for the delay on the first shot)
  140. reloadmax = 10; //sets the reload max
  141. reloadtick = 0; //sets the reloadtick to 0
  142. this.ammo = 10; //sets the ammo
  143. this.clipid = 4599; //sets the clipid
  144. this.firesound = firesound; //sets the firesound
  145. this.reloadsound = reloadsound; //sets the reloadsound
  146. setMaxStackSize(1); //sets the max stack size to one
  147. setMaxDamage(ammo + 1); //sets the durability of our gun to the ammo count + 1
  148. }
  149.  
  150. public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){
  151.  
  152. //Checks if the player has enough ammo
  153. if(!par2World.isRemote && par1ItemStack.getItemDamage() < ammo){
  154.  
  155. //if the firemax isn't 0, and the fireing counter is done, then this is true
  156. if(firetick == firemax && firemax != 0){
  157.  
  158. //spawns the bullet
  159. par2World.spawnEntityInWorld(new Entitybullet(par2World, par3EntityPlayer, damage, 1));
  160. //plays the sound effect
  161. par2World.playSoundAtEntity(par3EntityPlayer, firesound, 1F, 1F);
  162. //damages the gun
  163. par1ItemStack.damageItem(1, par3EntityPlayer);
  164. //resets the fire delay counter
  165. firetick = 0;
  166.  
  167. }else{
  168.  
  169. //if the fire delay counter isn't done, then this is called, which increases the fire delay counter
  170. ++firetick;
  171. }
  172.  
  173. //if firemax is 0 none of the above was called, so call this instead
  174. if(firemax == 0){
  175.  
  176. par2World.spawnEntityInWorld(new Entitybullet(par2World, par3EntityPlayer, damage, 1));
  177. par2World.playSoundAtEntity(par3EntityPlayer, firesound, 1F, 1F);
  178. par1ItemStack.damageItem(1, par3EntityPlayer);
  179. //already explained...
  180. }
  181.  
  182. //If the player is out of ammo in the current clip, and the player has the correct clip, run this code
  183. }else if(!par2World.isRemote && par3EntityPlayer.inventory.hasItem(clipid) && par1ItemStack.getItemDamage() == ammo){
  184.  
  185. //checks for the reload timer to complete
  186. if(reloadtick == reloadmax){
  187.  
  188. //resets the reload timer
  189. reloadtick = 0;
  190. //plays the reload sound
  191. par2World.playSoundAtEntity(par3EntityPlayer, reloadsound, 1F, 1F);
  192. //consumes the item of the clipid
  193. par3EntityPlayer.inventory.consumeInventoryItem(clipid);
  194. //resets the ammo of the gun
  195. par1ItemStack.setItemDamage(0);
  196.  
  197. }else{
  198.  
  199. //just like with firetick and firemax...
  200. ++reloadtick;
  201. }
  202. }
  203.  
  204. //just some housekeeping stuff
  205. return par1ItemStack;
  206. }
  207.  
  208. public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int i){
  209.  
  210. //this resets the firetick. I originally planned on using this method for non-automatic weapons
  211. //but the method didn't seem to end up being called at all... if someone could clarify why this is
  212. //happening I would appreciate it...
  213. firetick = firemax;
  214. }
  215. public String getTextureFile(){
  216. return "/****.png";
  217.  
  218. }
  219.  
  220. }
  221.  
  222.  
  223.  
  224. ----------------------------------Entitybullet----------------------------------------------
  225. package ****;
  226. import java.util.List;
  227. import java.util.Random;
  228.  
  229. import net.minecraft.block.Block;
  230. import net.minecraft.client.Minecraft;
  231. import net.minecraft.entity.Entity;
  232. import net.minecraft.entity.EntityLiving;
  233. import net.minecraft.entity.player.EntityPlayer;
  234. import net.minecraft.item.Item;
  235. import net.minecraft.item.ItemStack;
  236. import net.minecraft.nbt.NBTTagCompound;
  237. import net.minecraft.util.AxisAlignedBB;
  238. import net.minecraft.util.EntityDamageSource;
  239. import net.minecraft.util.MathHelper;
  240. import net.minecraft.util.MovingObjectPosition;
  241. import net.minecraft.util.Vec3;
  242. import net.minecraft.world.World;
  243. public class Entitybullet extends Entity
  244. {
  245. private int xTile;
  246. private int yTile;
  247. private int zTile;
  248. private int inTile;
  249. private boolean inGround;
  250. public int arrowShake;
  251. public EntityLiving shootingEntity;
  252. private int timeTillDeath;
  253. private int flyTime;
  254. private EntityPlayer owner;
  255. private int damage;
  256. private final float size = 1F;
  257.  
  258. public Entitybullet(World world)
  259. {
  260. super(world);
  261. xTile = -1;
  262. yTile = -1;
  263. zTile = -1;
  264. inTile = 0;
  265. inGround = false;
  266. arrowShake = 0;
  267. flyTime = 0;
  268. setSize(size, size);
  269. }
  270. public Entitybullet(World world, double d, double d1, double d2,
  271. double d3, double d4, double d5, EntityPlayer entityplayer)
  272. {
  273. super(world);
  274. xTile = -1;
  275. yTile = -1;
  276. zTile = -1;
  277. inTile = 0;
  278. inGround = false;
  279. arrowShake = 0;
  280. flyTime = 0;
  281. setSize(size, size);
  282. setPosition(d, d1, d2);
  283. yOffset = 0.0F;
  284. setVelocity(d3, d4, d5);
  285. owner = entityplayer;
  286. }
  287. public Entitybullet(World world, double d, double d1, double d2)
  288. {
  289. super(world);
  290. xTile = -1;
  291. yTile = -1;
  292. zTile = -1;
  293. inTile = 0;
  294. inGround = false;
  295. arrowShake = 0;
  296. flyTime = 0;
  297. setSize(size, size);
  298. setPosition(d, d1, d2);
  299. yOffset = 0.0F;
  300. }
  301. public Entitybullet(World world, EntityLiving entityliving, int damage, int accuracy)
  302. {
  303. super(world);
  304. this.damage = damage;
  305. xTile = -1;
  306. yTile = -1;
  307. zTile = -1;
  308. inTile = 0;
  309. inGround = false;
  310. arrowShake = 0;
  311. flyTime = 0;
  312. shootingEntity = entityliving;
  313. setSize(size, size);
  314. setLocationAndAngles(entityliving.posX, entityliving.posY + (double)entityliving.getEyeHeight(), entityliving.posZ, entityliving.rotationYaw, entityliving.rotationPitch);
  315. posX -= MathHelper.cos((rotationYaw / 180F) * 3.141593F) * 0.16F;
  316. posY -= 0.10000000149011612D;
  317. posZ -= MathHelper.sin((rotationYaw / 180F) * 3.141593F) * 0.16F;
  318. setPosition(posX, posY, posZ);
  319. yOffset = 0.0F;
  320. motionX = 1000F * -MathHelper.sin((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
  321. motionZ = 1000F * MathHelper.cos((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
  322. motionY = 1000F * -MathHelper.sin((rotationPitch / 180F) * 3.141593F);
  323. setArrowHeading(motionX, motionY, motionZ, 200.0F, 1.5F, accuracy);
  324. }
  325. protected void entityInit()
  326. {
  327. }
  328. public void setArrowHeading(double d, double d1, double d2, float f,
  329. float f1, int i)
  330. {
  331. float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
  332. d /= f2;
  333. d1 /= f2;
  334. d2 /= f2;
  335. d += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
  336. d1 += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
  337. d2 += rand.nextGaussian() * 0.0034999998323619365D * (double)f1 * (double)i / 5;
  338. d *= f;
  339. d1 *= f;
  340. d2 *= f;
  341. motionX = d;
  342. motionY = d1;
  343. motionZ = d2;
  344. float f3 = MathHelper.sqrt_double(d * d + d2 * d2);
  345. prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
  346. prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f3) * 180D) / 3.1415927410125732D);
  347. timeTillDeath = 0;
  348. }
  349. public void setVelocity(double d, double d1, double d2)
  350. {
  351. motionX = d;
  352. motionY = d1;
  353. motionZ = d2;
  354. if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
  355. {
  356. float f = MathHelper.sqrt_double(d * d + d2 * d2);
  357. prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
  358. prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f) * 180D) / 3.1415927410125732D);
  359. }
  360. }
  361. public void onUpdate()
  362. {
  363. super.onUpdate();
  364. if (flyTime > 1000)
  365. {
  366. setDead();
  367. }
  368. if (prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
  369. {
  370. float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  371. prevRotationYaw = rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
  372. prevRotationPitch = rotationPitch = (float)((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D);
  373. }
  374. if (arrowShake > 0)
  375. {
  376. arrowShake--;
  377. }
  378. if (inGround)
  379. {
  380. int i = worldObj.getBlockId(xTile, yTile, zTile);
  381. if (i != inTile)
  382. {
  383. inGround = false;
  384. motionX *= rand.nextFloat() * 0.2F;
  385. motionY *= rand.nextFloat() * 0.2F;
  386. motionZ *= rand.nextFloat() * 0.2F;
  387. timeTillDeath = 0;
  388. flyTime = 0;
  389. }
  390. else
  391. {
  392. timeTillDeath++;
  393. if (timeTillDeath == 1200)
  394. {
  395. setDead();
  396. }
  397. return;
  398. }
  399. }
  400. else
  401. {
  402. flyTime++;
  403. }
  404. Vec3 vec3d = Vec3.createVectorHelper(posX, posY, posZ);
  405. Vec3 vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
  406. MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
  407. vec3d = Vec3.createVectorHelper(posX, posY, posZ);
  408. vec3d1 = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
  409. if (movingobjectposition != null)
  410. {
  411. vec3d1 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
  412. }
  413. Entity entity = null;
  414. List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
  415. double d = 0.0D;
  416. for (int j = 0; j < list.size(); j++)
  417. {
  418. Entity entity1 = (Entity)list.get(j);
  419. if (!entity1.canBeCollidedWith() || entity1 == shootingEntity && flyTime < 5)
  420. {
  421. continue;
  422. }
  423. float f4 = 0.3F;
  424. AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f4, f4, f4);
  425. MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
  426. if (movingobjectposition1 == null)
  427. {
  428. continue;
  429. }
  430. double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
  431. if (d1 < d || d == 0.0D)
  432. {
  433. entity = entity1;
  434. d = d1;
  435. }
  436. }
  437. if (entity != null)
  438. {
  439. movingobjectposition = new MovingObjectPosition(entity);
  440. }
  441. if (movingobjectposition != null)
  442. {
  443. if (movingobjectposition.entityHit != null)
  444. {
  445. if (movingobjectposition.entityHit.attackEntityFrom(new EntityDamageSource("player", owner), damage))
  446. {
  447. worldObj.playSoundAtEntity(this, "random.hurt", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
  448. setDead();
  449. }
  450. else
  451. {
  452. motionX *= 0.10000000149011612D;
  453. motionY *= 0.10000000149011612D;
  454. motionZ *= 0.10000000149011612D;
  455. flyTime = 0;
  456. setDead();
  457. }
  458. }
  459. else
  460. {
  461. xTile = movingobjectposition.blockX;
  462. yTile = movingobjectposition.blockY;
  463. zTile = movingobjectposition.blockZ;
  464. inTile = worldObj.getBlockId(xTile, yTile, zTile);
  465. if (inTile == Block.glass.blockID || inTile == Block.glowStone.blockID)
  466. {
  467. Block block = Block.blocksList[inTile];
  468. //ModLoader.getMinecraftInstance().sndManager.playSound(block.stepSound.stepSoundDir(), (float)xTile + 0.5F, (float)yTile + 0.5F, (float)zTile + 0.5F, (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
  469. worldObj.setBlockWithNotify(xTile, yTile, zTile, 0);
  470. }
  471. else
  472. {
  473. motionX = (float)(movingobjectposition.hitVec.xCoord - posX);
  474. motionY = (float)(movingobjectposition.hitVec.yCoord - posY);
  475. motionZ = (float)(movingobjectposition.hitVec.zCoord - posZ);
  476. float f1 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);
  477. posX -= (motionX / (double)f1) * 0.05000000074505806D;
  478. posY -= (motionY / (double)f1) * 0.05000000074505806D;
  479. posZ -= (motionZ / (double)f1) * 0.05000000074505806D;
  480. worldObj.playSoundAtEntity(this, "Bullet2Hit", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
  481. setDead();
  482. }
  483. }
  484. }
  485. posX += motionX * 3D;
  486. posY += motionY * 3D;
  487. posZ += motionZ * 3D;
  488. float f2 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  489. rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
  490. for (rotationPitch = (float)((Math.atan2(motionY, f2) * 180D) / 3.1415927410125732D); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) { }
  491. for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) { }
  492. for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) { }
  493. for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) { }
  494. rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
  495. rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
  496. float f3 = 0.99F;
  497. float f5 = 0.03F;
  498. if (handleWaterMovement())
  499. {
  500. for (int k = 0; k < 4; k++)
  501. {
  502. float f6 = 0.25F;
  503. worldObj.spawnParticle("smoke", posX - motionX * (double)f6, posY - motionY * (double)f6, posZ - motionZ * (double)f6, motionX, motionY, motionZ);
  504. }
  505. f3 = 0.8F;
  506. }
  507. motionX *= f3;
  508. motionY *= f3;
  509. motionZ *= f3;
  510. setPosition(posX, posY, posZ);
  511. }
  512. public void writeEntityToNBT1(NBTTagCompound nbttagcompound)
  513. {
  514. nbttagcompound.setShort("xTile", (short)xTile);
  515. nbttagcompound.setShort("yTile", (short)yTile);
  516. nbttagcompound.setShort("zTile", (short)zTile);
  517. nbttagcompound.setByte("inTile", (byte)inTile);
  518. nbttagcompound.setByte("shake", (byte)arrowShake);
  519. nbttagcompound.setByte("inGround", (byte)(inGround ? 1 : 0));
  520. }
  521. public void readEntityFromNBT1(NBTTagCompound nbttagcompound)
  522. {
  523. xTile = nbttagcompound.getShort("xTile");
  524. yTile = nbttagcompound.getShort("yTile");
  525. zTile = nbttagcompound.getShort("zTile");
  526. inTile = nbttagcompound.getByte("inTile") & 0xff;
  527. arrowShake = nbttagcompound.getByte("shake") & 0xff;
  528. inGround = nbttagcompound.getByte("inGround") == 1;
  529. }
  530. public void onCollideWithPlayer(EntityPlayer entityplayer)
  531. {
  532. if (worldObj.isRemote)
  533. {
  534. return;
  535. }
  536. if (inGround && shootingEntity == entityplayer && arrowShake <= 0 && entityplayer.inventory.addItemStackToInventory(new ItemStack(Item.arrow, 1)))
  537. {
  538. worldObj.playSoundAtEntity(this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
  539. entityplayer.onItemPickup(this, 1);
  540. setDead();
  541. }
  542. }
  543. public float getShadowSize()
  544. {
  545. return 0.0F;
  546. }
  547. @Override
  548. protected void readEntityFromNBT(NBTTagCompound var1) {
  549.  
  550. }
  551. @Override
  552. protected void writeEntityToNBT(NBTTagCompound var1) {
  553.  
  554. }
  555. {
  556. this.worldObj.spawnParticle("smoke", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
  557. }
  558.  
  559.  
  560. }
  561.  
  562.  
  563. ---------------------------Itemgrenade------------------------------------
  564. package ****;
  565.  
  566. import net.minecraft.creativetab.CreativeTabs;
  567. import net.minecraft.entity.player.EntityPlayer;
  568. import net.minecraft.item.Item;
  569. import net.minecraft.item.ItemStack;
  570. import net.minecraft.world.World;
  571.  
  572. public class Itemgrenade extends Item
  573. {
  574.  
  575. public Itemgrenade(int i)
  576. {
  577. super(i);
  578. this.maxStackSize = 4;
  579. this.setCreativeTab(CreativeTabs.tabCombat);
  580. }
  581.  
  582. public ItemStack onItemRightClick(ItemStack var1, World var2, EntityPlayer var3)
  583. {
  584. if (!var3.capabilities.isCreativeMode)
  585. {
  586. --var1.stackSize;
  587. }
  588. var2.playSoundAtEntity(var3, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  589. if (!var2.isRemote)
  590. {
  591. var2.spawnEntityInWorld(new Entitygrenade(var2, var3));
  592. }
  593. return var1;
  594. }
  595.  
  596. public String getTextureFile()
  597. {
  598. return "/****.png";
  599. }
  600.  
  601. }
  602.  
  603. ----------------------------------------Entitygrenade-------------------------------
  604.  
  605. package ****;
  606.  
  607. import net.minecraft.entity.Entity;
  608. import net.minecraft.entity.EntityLiving;
  609. import net.minecraft.entity.projectile.EntityThrowable;
  610. import net.minecraft.util.DamageSource;
  611. import net.minecraft.util.MovingObjectPosition;
  612. import net.minecraft.world.World;
  613.  
  614. public class Entitygrenade extends Entitybombthrow
  615. {
  616. private static final int var2 = 0;
  617. private EntityLiving thrower;
  618. public Entitygrenade(World var1)
  619. {
  620. super(var1);
  621. }
  622. public Entitygrenade(World var1, EntityLiving var2)
  623. {
  624. super(var1, var2);
  625. }
  626. public Entitygrenade(World var1, double var2, double var4, double var6)
  627. {
  628. super(var1, var2, var4, var6);
  629. }
  630. /**
  631. * Called when this EntityThrowable hits a block or entity.
  632. */
  633. protected void onImpact(MovingObjectPosition var1)
  634. {
  635. if (var1.entityHit != null)
  636. {
  637.  
  638. {
  639.  
  640. }
  641. if (!var1.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.thrower), var2))
  642. {
  643. ;
  644. }
  645. }
  646. for (int var3 = 0; var3 < 8; ++var3)
  647. {
  648. this.worldObj.spawnParticle("smoke", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
  649.  
  650. }
  651. if (!this.worldObj.isRemote)
  652. {
  653. this.setDead();
  654. if (!this.worldObj.isRemote)
  655. {
  656. this.worldObj.createExplosion((Entity)null, this.posX, this.posY, this.posZ, 2.0F, true);
  657. }
  658. }
  659. }
  660.  
  661. public String getTextureFile()
  662. {
  663. return "/****.png";
  664. }
  665.  
  666. }
Advertisement
Add Comment
Please, Sign In to add comment