drackiseries

A New Cactus

Jul 27th, 2012
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.06 KB | None | 0 0
  1. MOD_ FILE CONTENTS:
  2.  
  3.  
  4. package net.minecraft.src;
  5.  
  6. import java.util.Random;
  7.  
  8. public class mod_tutorial extends BaseMod
  9. {
  10.     //Textures
  11.    
  12.     public static int SoulCactusSide = ModLoader.addOverride("/terrain.png","/Blocks/soulcactusside.png");
  13.     public static int SoulCactusTop = ModLoader.addOverride("/terrain.png","/Blocks/soulcactustop.png");
  14.     public static int SoulCactusBottom = ModLoader.addOverride("/terrain.png","/Blocks/soulcactusbottom.png");
  15.    
  16.     //Blocks
  17.    
  18. public static final Block SoulCactus = (new BlockSoulCactus(200,0).setHardness(0.4F).setStepSound(Block.soundClothFootstep).setBlockName("SoulCactus"));
  19.    
  20.     //Tree Blocks
  21.    
  22.     //Very Complex Blocks
  23.    
  24.     //Items
  25.    
  26.  
  27.     public void load()
  28.     {
  29.        
  30.        
  31.    
  32.         //Registering
  33.    
  34.         ModLoader.registerBlock(SoulCactus);
  35.        
  36.        
  37.         //Adding names
  38.        
  39.         ModLoader.addName(SoulCactus, "Soul Cactus");
  40.        
  41.        
  42.         //Tile Entity
  43.        
  44.         //Biomes
  45.        
  46.         ModLoader.addBiome(BiomeGenBase.souldesert);
  47.        
  48.         //Crafting Recipes
  49.        
  50.         //Smelting Recipes
  51.        
  52.         //Shapeless Recipes
  53.        
  54.        
  55.        
  56.        
  57.     }
  58.  
  59.    
  60.  
  61.    
  62.     public String getVersion()
  63.     {
  64.         return "1.2.5";
  65.     }
  66. }
  67.  
  68. BLOCKSOULCACTUS FILE:
  69.  
  70.  
  71. package net.minecraft.src;
  72.  
  73. import java.util.Random;
  74.  
  75. public class BlockSoulCactus extends Block
  76. {
  77.     protected BlockSoulCactus(int par1, int par2)
  78.     {
  79.         super(par1, par2, Material.cactus);
  80.         setTickRandomly(true);
  81.     }
  82.  
  83.     /**
  84.      * Ticks the block if it's been scheduled
  85.      */
  86.     public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
  87.     {
  88.         if (par1World.isAirBlock(par2, par3 + 1, par4))
  89.         {
  90.             int i;
  91.  
  92.             for (i = 1; par1World.getBlockId(par2, par3 - i, par4) == blockID; i++) { }
  93.  
  94.             if (i < 3)
  95.             {
  96.                 int j = par1World.getBlockMetadata(par2, par3, par4);
  97.  
  98.                 if (j == 15)
  99.                 {
  100.                     par1World.setBlockWithNotify(par2, par3 + 1, par4, blockID);
  101.                     par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
  102.                 }
  103.                 else
  104.                 {
  105.                     par1World.setBlockMetadataWithNotify(par2, par3, par4, j + 1);
  106.                 }
  107.             }
  108.         }
  109.     }
  110.  
  111.     /**
  112.      * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
  113.      * cleared to be reused)
  114.      */
  115.     public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
  116.     {
  117.         float f = 0.0625F;
  118.         return AxisAlignedBB.getBoundingBoxFromPool((float)par2 + f, par3, (float)par4 + f, (float)(par2 + 1) - f, (float)(par3 + 1) - f, (float)(par4 + 1) - f);
  119.     }
  120.  
  121.     /**
  122.      * Returns the bounding box of the wired rectangular prism to render.
  123.      */
  124.     public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
  125.     {
  126.         float f = 0.0625F;
  127.         return AxisAlignedBB.getBoundingBoxFromPool((float)par2 + f, par3, (float)par4 + f, (float)(par2 + 1) - f, par3 + 1, (float)(par4 + 1) - f);
  128.     }
  129.  
  130.     /**
  131.      * Returns the block texture based on the side being looked at.  Args: side
  132.      */
  133.     public int getBlockTextureFromSide(int par1)
  134.     {
  135.         if (par1 == 1)
  136.         {
  137.             return mod_tutorial.SoulCactusTop;
  138.         }
  139.  
  140.         if (par1 == 0)
  141.         {
  142.             return mod_tutorial.SoulCactusBottom;
  143.         }
  144.         else
  145.         {
  146.             return mod_tutorial.SoulCactusSide;
  147.         }
  148.     }
  149.  
  150.     /**
  151.      * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
  152.      */
  153.     public boolean renderAsNormalBlock()
  154.     {
  155.         return false;
  156.     }
  157.  
  158.     /**
  159.      * Is this block (a) opaque and (b) a full 1m cube?  This determines whether or not to render the shared face of two
  160.      * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
  161.      */
  162.     public boolean isOpaqueCube()
  163.     {
  164.         return false;
  165.     }
  166.  
  167.     /**
  168.      * The type of render function that is called for this block
  169.      */
  170.     public int getRenderType()
  171.     {
  172.         return 13;
  173.     }
  174.  
  175.     /**
  176.      * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
  177.      */
  178.     public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
  179.     {
  180.         if (!super.canPlaceBlockAt(par1World, par2, par3, par4))
  181.         {
  182.             return false;
  183.         }
  184.         else
  185.         {
  186.             return canBlockStay(par1World, par2, par3, par4);
  187.         }
  188.     }
  189.  
  190.     /**
  191.      * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
  192.      * their own) Args: x, y, z, neighbor blockID
  193.      */
  194.     public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
  195.     {
  196.         if (!canBlockStay(par1World, par2, par3, par4))
  197.         {
  198.             dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
  199.             par1World.setBlockWithNotify(par2, par3, par4, 0);
  200.         }
  201.     }
  202.  
  203.     /**
  204.      * Can this block stay at this position.  Similar to canPlaceBlockAt except gets checked often with plants.
  205.      */
  206.     public boolean canBlockStay(World par1World, int par2, int par3, int par4)
  207.     {
  208.         if (par1World.getBlockMaterial(par2 - 1, par3, par4).isSolid())
  209.         {
  210.             return false;
  211.         }
  212.  
  213.         if (par1World.getBlockMaterial(par2 + 1, par3, par4).isSolid())
  214.         {
  215.             return false;
  216.         }
  217.  
  218.         if (par1World.getBlockMaterial(par2, par3, par4 - 1).isSolid())
  219.         {
  220.             return false;
  221.         }
  222.  
  223.         if (par1World.getBlockMaterial(par2, par3, par4 + 1).isSolid())
  224.         {
  225.             return false;
  226.         }
  227.         else
  228.         {
  229.             int i = par1World.getBlockId(par2, par3 - 1, par4);
  230.             return i == mod_tutorial.SoulCactus.blockID || i == Block.slowSand.blockID;
  231.         }
  232.     }
  233.  
  234.     /**
  235.      * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
  236.      */
  237.     public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)
  238.     {
  239.         par5Entity.attackEntityFrom(DamageSource.cactus, 1);
  240.     }
  241. }
  242.  
  243. WORLDGENSOULCACTUS FILE:
  244. ========================
  245.  
  246.  
  247. package net.minecraft.src;
  248.  
  249. import java.util.Random;
  250.  
  251. public class WorldGenSoulCactus extends WorldGenerator
  252. {
  253.     public WorldGenSoulCactus()
  254.     {
  255.     }
  256.  
  257.     public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
  258.     {
  259.         for (int i = 0; i < 10; i++)
  260.         {
  261.             int j = (par3 + par2Random.nextInt(8)) - par2Random.nextInt(8);
  262.             int k = (par4 + par2Random.nextInt(4)) - par2Random.nextInt(4);
  263.             int l = (par5 + par2Random.nextInt(8)) - par2Random.nextInt(8);
  264.  
  265.             if (!par1World.isAirBlock(j, k, l))
  266.             {
  267.                 continue;
  268.             }
  269.  
  270.             int i1 = 1 + par2Random.nextInt(par2Random.nextInt(3) + 1);
  271.  
  272.             for (int j1 = 0; j1 < i1; j1++)
  273.             {
  274.                 if (mod_tutorial.SoulCactus.canBlockStay(par1World, j, k + j1, l))
  275.                 {
  276.                     par1World.setBlock(j, k + j1, l, mod_tutorial.SoulCactus.blockID);
  277.                 }
  278.             }
  279.         }
  280.  
  281.         return true;
  282.     }
  283. }
  284.  
  285. BIOME DECORATOR STUFF:
  286.  
  287. protected int soulcactusperchunk; // ADD THIS OUTSIDE OF PUBLIC BIOMEDECORATOR(BiomeGenBasepar1BiomeGenBase)
  288.  
  289. soulcactusperchunk = 0; // ADD THIS INSIDE OF PUBLIC BIOMEDECORATOR(BiomeGenBasepar1BiomeGenBase)
  290.  
  291. ADD THIS TO THE DECORATE METHOD:
  292. for (int u = 0; u < soulcactusperchunk; u++)
  293.         {
  294.             int a100 = chunk_X + randomGenerator.nextInt(16) + 8;
  295.             int a101 = randomGenerator.nextInt(128);
  296.             int a102 = chunk_Z + randomGenerator.nextInt(16) + 8;
  297.             (new WorldGenSoulCactus()).generate(currentWorld, randomGenerator, a100, a101, a102);
  298.         }
Advertisement
Add Comment
Please, Sign In to add comment