TGAM123

mod_mooncraft

Apr 7th, 2011
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.68 KB | None | 0 0
  1. mod_MoonCraft:
  2. package net.minecraft.src;
  3.  
  4. import java.util.Random;
  5. import java.util.Map;
  6.  
  7. public class mod_MoonCraft extends BaseMod {
  8.  
  9. public String Version()
  10. {
  11.      return "1.4_01";
  12. }
  13.  
  14. public mod_MoonCraft()
  15. {
  16.  
  17.     ModLoader.AddRecipe(new ItemStack(moonStone, 4), new Object[] {
  18.         "X#", "#X", Character.valueOf('#'), Block.dirt, Character.valueOf('X'), Block.cobblestone
  19. });
  20.     ModLoader.AddRecipe(new ItemStack(moonGlass, 4), new Object[] {
  21.         "#", Character.valueOf('#'), moonStone
  22. });
  23.     ModLoader.AddRecipe(new ItemStack(moonTorch, 16), new Object[] {
  24.         "#", "X", Character.valueOf('X'), moonStone, Character.valueOf('#'), Item.ingotIron
  25. });
  26.     ModLoader.AddRecipe(new ItemStack(bullet, 8), new Object[] {
  27.         "X##", Character.valueOf('X'), moonGlass, Character.valueOf('#'), moonStone
  28. });
  29.     ModLoader.AddRecipe(new ItemStack(moonGun, 1), new Object[] {
  30.         " X ", "###", "  #", Character.valueOf('X'), moonGlass, Character.valueOf('#'), moonStone
  31. });
  32. //Item.pickaxeSteel
  33.  
  34. }
  35.  
  36. public static final Block moonStone = (new BlockMoonStone(120, 106)).setHardness(0.3F).setStepSound(soundStoneFootstep).setLightValue(1.0F).setBlockName("moonStone");
  37. public static final Block moonGlass = (new BlockMoonGlass(121, 107)).setHardness(0.1F).setStepSound(soundStoneFootstep).setLightValue(1.0F).setBlockName("moonGlass");
  38. public static final Block moonTorch = (new BlockMoonTorch(122, 108)).setHardness(0F).setStepSound(soundStoneFootstep).setLightValue(2.0F).setBlockName("moonTorch");
  39. public static final Item bullet = (new Item(6)).setIconCoord(5, 5).setItemName("bullet");
  40. public static final Item moonGun = (new ItemMoonGun(5)).setIconCoord(5, 6).setItemName("moonGun");
  41.  
  42.     public void AddRenderer(Map map)
  43.     {
  44.         map.put(EntityBullet.class, new RenderBullet());
  45.     }
  46.  
  47. }
  48.  
  49. moonGun:
  50. package net.minecraft.src;
  51. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  52. // Jad home page: http://www.kpdus.com/jad.html
  53. // Decompiler options: packimports(3) braces deadcode
  54.  
  55. import java.util.Random;
  56.  
  57. public class ItemMoonGun extends Item
  58. {
  59.  
  60.     public ItemMoonGun(int i)
  61.     {
  62.         super(i);
  63.         maxStackSize = 1;
  64.     }
  65.  
  66.     public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
  67.     {
  68.         if(entityplayer.inventory.consumeInventoryItem(mod_MoonCraft.bullet.shiftedIndex))
  69.         {
  70.             world.playSoundAtEntity(entityplayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
  71.             if(!world.multiplayerWorld)
  72.             {
  73.                 world.entityJoinedWorld(new EntityBullet(world, entityplayer));
  74.             }
  75.         }
  76.         return itemstack;
  77.     }
  78. }
  79.  
  80. Bullet:
  81. package net.minecraft.src;
  82. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  83. // Jad home page: http://www.kpdus.com/jad.html
  84. // Decompiler options: packimports(3) braces deadcode
  85.  
  86. import java.util.List;
  87. import java.util.Random;
  88.  
  89. public class EntityBullet extends Entity
  90. {
  91.  
  92.     public EntityBullet(World world)
  93.     {
  94.         super(world);
  95.         xTile = -1;
  96.         yTile = -1;
  97.         zTile = -1;
  98.         inTile = 0;
  99.         inGround = false;
  100.         arrowShake = 0;
  101.         flyTime = 0;
  102.         setSize(0.5F, 0.5F);
  103.     }
  104.  
  105.     public EntityBullet(World world, double d, double d1, double d2)
  106.     {
  107.         super(world);
  108.         xTile = -1;
  109.         yTile = -1;
  110.         zTile = -1;
  111.         inTile = 0;
  112.         inGround = false;
  113.         arrowShake = 0;
  114.         flyTime = 0;
  115.         setSize(0.5F, 0.5F);
  116.         setPosition(d, d1, d2);
  117.         yOffset = 0.0F;
  118.     }
  119.  
  120.     public EntityBullet(World world, EntityLiving entityliving)
  121.     {
  122.         super(world);
  123.         xTile = -1;
  124.         yTile = -1;
  125.         zTile = -1;
  126.         inTile = 0;
  127.         inGround = false;
  128.         arrowShake = 0;
  129.         flyTime = 0;
  130.         field_682_g = entityliving;
  131.         setSize(0.5F, 0.5F);
  132.         setLocationAndAngles(entityliving.posX, entityliving.posY + (double)entityliving.getEyeHeight(), entityliving.posZ, entityliving.rotationYaw, entityliving.rotationPitch);
  133.         posX -= MathHelper.cos((rotationYaw / 180F) * 3.141593F) * 0.16F;
  134.         posY -= 0D;
  135.         posZ -= MathHelper.sin((rotationYaw / 180F) * 3.141593F) * 0.16F;
  136.         setPosition(posX, posY, posZ);
  137.         yOffset = 0.0F;
  138.         motionX = -MathHelper.sin((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
  139.         motionZ = MathHelper.cos((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
  140.         motionY = -MathHelper.sin((rotationPitch / 180F) * 3.141593F);
  141.         setArrowHeading(motionX, motionY, motionZ, 5F, 5F);
  142.     }
  143.  
  144.     protected void entityInit()
  145.     {
  146.     }
  147.  
  148.     public void setArrowHeading(double d, double d1, double d2, float f,
  149.             float f1)
  150.     {
  151.         float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
  152.         d /= f2;
  153.         d1 /= f2;
  154.         d2 /= f2;
  155.         d += rand.nextGaussian() * 0D * (double)f1;
  156.         d1 += rand.nextGaussian() * 0D * (double)f1;
  157.         d2 += rand.nextGaussian() * 0D * (double)f1;
  158.         d *= f;
  159.         d1 *= f;
  160.         d2 *= f;
  161.         motionX = d;
  162.         motionY = d1;
  163.         motionZ = d2;
  164.         float f3 = MathHelper.sqrt_double(d * d + d2 * d2);
  165.         prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
  166.         prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f3) * 180D) / 3.1415927410125732D);
  167.         timeTillDeath = 0;
  168.     }
  169.  
  170.     public void setVelocity(double d, double d1, double d2)
  171.     {
  172.         motionX = d;
  173.         motionY = d1;
  174.         motionZ = d2;
  175.         if(prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
  176.         {
  177.             float f = MathHelper.sqrt_double(d * d + d2 * d2);
  178.             prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
  179.             prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f) * 180D) / 3.1415927410125732D);
  180.         }
  181.     }
  182.  
  183.     public void onUpdate()
  184.     {
  185.         super.onUpdate();
  186.         if(prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
  187.         {
  188.             float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  189.             prevRotationYaw = rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
  190.             prevRotationPitch = rotationPitch = (float)((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D);
  191.         }
  192.         if(arrowShake > 0)
  193.         {
  194.             arrowShake--;
  195.         }
  196.         if(inGround)
  197.         {
  198.             int i = worldObj.getBlockId(xTile, yTile, zTile);
  199.             if(i != inTile)
  200.             {
  201.                 inGround = false;
  202.                 motionX *= rand.nextFloat() * 0.05F;
  203.                 motionY *= rand.nextFloat() * 0.05F;
  204.                 motionZ *= rand.nextFloat() * 0.05F;
  205.                 timeTillDeath = 0;
  206.                 flyTime = 0;
  207.             } else
  208.             {
  209.                 timeTillDeath++;
  210.                 if(timeTillDeath == 1200)
  211.                 {
  212.                     setEntityDead();
  213.                 }
  214.                 return;
  215.             }
  216.         } else
  217.         {
  218.             flyTime++;
  219.         }
  220.         Vec3D vec3d = Vec3D.createVector(posX, posY, posZ);
  221.         Vec3D vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);
  222.         MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
  223.         vec3d = Vec3D.createVector(posX, posY, posZ);
  224.         vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);
  225.         if(movingobjectposition != null)
  226.         {
  227.             vec3d1 = Vec3D.createVector(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
  228.         }
  229.         Entity entity = null;
  230.         List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
  231.         double d = 0.0D;
  232.         for(int j = 0; j < list.size(); j++)
  233.         {
  234.             Entity entity1 = (Entity)list.get(j);
  235.             if(!entity1.canBeCollidedWith() || entity1 == field_682_g && flyTime < 5)
  236.             {
  237.                 continue;
  238.             }
  239.             float f4 = 0.3F;
  240.             AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f4, f4, f4);
  241.             MovingObjectPosition movingobjectposition1 = axisalignedbb.func_1169_a(vec3d, vec3d1);
  242.             if(movingobjectposition1 == null)
  243.             {
  244.                 continue;
  245.             }
  246.             double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
  247.             if(d1 < d || d == 0.0D)
  248.             {
  249.                 entity = entity1;
  250.                 d = d1;
  251.             }
  252.         }
  253.  
  254.         if(entity != null)
  255.         {
  256.             movingobjectposition = new MovingObjectPosition(entity);
  257.         }
  258.         if(movingobjectposition != null)
  259.         {
  260.             if(movingobjectposition.entityHit != null)
  261.             {
  262.                 if(movingobjectposition.entityHit.attackEntityFrom(field_682_g, 4))
  263.                 {
  264.                     worldObj.playSoundAtEntity(this, "random.drr", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
  265.                     setEntityDead();
  266.                 } else
  267.                 {
  268.                     motionX *= -0.10000000149011612D;
  269.                     motionY *= -0.10000000149011612D;
  270.                     motionZ *= -0.10000000149011612D;
  271.                     rotationYaw += 180F;
  272.                     prevRotationYaw += 180F;
  273.                     flyTime = 0;
  274.                 }
  275.             } else
  276.             {
  277.                 xTile = movingobjectposition.blockX;
  278.                 yTile = movingobjectposition.blockY;
  279.                 zTile = movingobjectposition.blockZ;
  280.                 inTile = worldObj.getBlockId(xTile, yTile, zTile);
  281.                 motionX = (float)(movingobjectposition.hitVec.xCoord - posX);
  282.                 motionY = (float)(movingobjectposition.hitVec.yCoord - posY);
  283.                 motionZ = (float)(movingobjectposition.hitVec.zCoord - posZ);
  284.                 float f1 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);
  285.                 posX -= (motionX / (double)f1) * 0.05000000074505806D;
  286.                 posY -= (motionY / (double)f1) * 0.05000000074505806D;
  287.                 posZ -= (motionZ / (double)f1) * 0.05000000074505806D;
  288.                 worldObj.playSoundAtEntity(this, "random.drr", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
  289.                 inGround = true;
  290.                 arrowShake = 7;
  291.             }
  292.         }
  293.         posX += motionX;
  294.         posY += motionY;
  295.         posZ += motionZ;
  296.         float f2 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  297.         rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
  298.         for(rotationPitch = (float)((Math.atan2(motionY, f2) * 180D) / 3.1415927410125732D); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) { }
  299.         for(; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) { }
  300.         for(; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) { }
  301.         for(; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) { }
  302.         rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
  303.         rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
  304.         float f3 = 0.99F;
  305.         float f5 = 0.03F;
  306.         if(handleWaterMovement())
  307.         {
  308.             for(int k = 0; k < 4; k++)
  309.             {
  310.                 float f6 = 0.25F;
  311.                 worldObj.spawnParticle("bubble", posX - motionX * (double)f6, posY - motionY * (double)f6, posZ - motionZ * (double)f6, motionX, motionY, motionZ);
  312.             }
  313.  
  314.             f3 = 0.8F;
  315.         }
  316.         motionX *= f3;
  317.         motionY *= f3;
  318.         motionZ *= f3;
  319.         motionY -= f5;
  320.         setPosition(posX, posY, posZ);
  321.     }
  322.  
  323.     public void writeEntityToNBT(NBTTagCompound nbttagcompound)
  324.     {
  325.         nbttagcompound.setShort("xTile", (short)xTile);
  326.         nbttagcompound.setShort("yTile", (short)yTile);
  327.         nbttagcompound.setShort("zTile", (short)zTile);
  328.         nbttagcompound.setByte("inTile", (byte)inTile);
  329.         nbttagcompound.setByte("shake", (byte)arrowShake);
  330.         nbttagcompound.setByte("inGround", (byte)(inGround ? 1 : 0));
  331.     }
  332.  
  333.     public void readEntityFromNBT(NBTTagCompound nbttagcompound)
  334.     {
  335.         xTile = nbttagcompound.getShort("xTile");
  336.         yTile = nbttagcompound.getShort("yTile");
  337.         zTile = nbttagcompound.getShort("zTile");
  338.         inTile = nbttagcompound.getByte("inTile") & 0xff;
  339.         arrowShake = nbttagcompound.getByte("shake") & 0xff;
  340.         inGround = nbttagcompound.getByte("inGround") == 1;
  341.     }
  342.  
  343.     public void onCollideWithPlayer(EntityPlayer entityplayer)
  344.     {
  345.         if(worldObj.multiplayerWorld)
  346.         {
  347.             return;
  348.         }
  349.         if(inGround && field_682_g == entityplayer && arrowShake <= 0 && entityplayer.inventory.addItemStackToInventory(new ItemStack(mod_MoonCraft.bullet, 1)))
  350.         {
  351.             worldObj.playSoundAtEntity(this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
  352.             entityplayer.onItemPickup(this, 1);
  353.             setEntityDead();
  354.         }
  355.     }
  356.  
  357.     public float getShadowSize()
  358.     {
  359.         return 0.0F;
  360.     }
  361.  
  362.     private int xTile;
  363.     private int yTile;
  364.     private int zTile;
  365.     private int inTile;
  366.     private boolean inGround;
  367.     public int arrowShake;
  368.     public EntityLiving field_682_g;
  369.     private int timeTillDeath;
  370.     private int flyTime;
  371. }
Advertisement
Add Comment
Please, Sign In to add comment