Guest User

BlockNori

a guest
Feb 12th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.24 KB | None | 0 0
  1. package com.chef.mod.crops;
  2.  
  3. import java.util.Random;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.block.IGrowable;
  7. import net.minecraft.block.material.Material;
  8. import net.minecraft.entity.EntityLivingBase;
  9. import net.minecraft.init.Blocks;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.AxisAlignedBB;
  13. import net.minecraft.world.IBlockAccess;
  14. import net.minecraft.world.World;
  15. import net.minecraftforge.common.EnumPlantType;
  16. import net.minecraftforge.common.IPlantable;
  17.  
  18. import com.chef.mod.init.MyBlocks;
  19. import com.chef.mod.init.MyItems;
  20.  
  21. import cpw.mods.fml.relauncher.Side;
  22. import cpw.mods.fml.relauncher.SideOnly;
  23.  
  24. public class BlockNori extends Block {
  25.  
  26.     float f = 0.375f;
  27.    
  28.     public BlockNori() {
  29.  
  30.         super(Material.water);
  31.         this.setStepSound(soundTypeGrass);
  32.         this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 1.0F, 0.5F + f);
  33.         this.setTickRandomly(true);
  34.  
  35.     }
  36.  
  37.     @Override
  38.     public boolean canPlaceBlockAt(World worldIn, int x, int y, int z) {
  39.  
  40.         Block ground = worldIn.getBlock(x, y - 1, z);
  41.         Block above = worldIn.getBlock(x, y + 1, z);
  42.  
  43.         if (ground == Blocks.gravel || ground == Blocks.dirt || ground == Blocks.sand || ground == MyBlocks.nori) {
  44.  
  45.             if (above == Blocks.water) {
  46.                
  47.                 return true;
  48.                
  49.             }
  50.  
  51.         }
  52.         return false;
  53.     }
  54.  
  55.     /**
  56.      * Called when a neighboring block changes.
  57.      */
  58.     public void onNeighborBlockChange(World worldIn, int x, int y, int z, Block neighborBlock) {
  59.  
  60.         this.checkForDrop(worldIn, x, y, z);
  61.  
  62.     }
  63.  
  64.     public void breakBlock(World worldIn, int x, int y, int z) {
  65.         worldIn.setBlock(x, y, z, Blocks.water);
  66.     }
  67.  
  68.     protected final boolean checkForDrop(World worldIn, int x, int y, int z) {
  69.  
  70.         if (this.canBlockStay(worldIn, x, y, z)) {
  71.  
  72.             return true;
  73.  
  74.         } else {
  75.  
  76.             this.dropBlockAsItem(worldIn, x, y, z, worldIn.getBlockMetadata(x, y, z), 0);
  77.             worldIn.setBlock(x, y, z, Blocks.water);
  78.             return false;
  79.  
  80.         }
  81.     }
  82.  
  83.     public boolean canBlockStay(World world, int x, int y, int z) {
  84.  
  85.         return this.canPlaceBlockAt(world, x, y, z);
  86.     }
  87.  
  88.     @Override
  89.     public AxisAlignedBB getCollisionBoundingBoxFromPool(World worldIn, int x, int y, int z) {
  90.         return null;
  91.     }
  92.  
  93.     @Override
  94.     public boolean isOpaqueCube() {
  95.         return false;
  96.     }
  97.  
  98.     @Override
  99.     public boolean renderAsNormalBlock() {
  100.         return false;
  101.     }
  102.  
  103.     @Override
  104.     public int getRenderType() {
  105.         return 1;
  106.     }
  107.  
  108.     @Override
  109.     public void updateTick(World worldIn, int x, int y, int z, Random rand) {
  110.  
  111.         if (worldIn.getBlock(x, y, z) == MyBlocks.nori) {
  112.  
  113.             if (worldIn.getBlock(x, y + 2, z) == Blocks.water) {
  114.  
  115.                 int i;
  116.  
  117.                 for (i = 1; worldIn.getBlock(x, y - i, z) == this; ++i) {
  118.                 }
  119.  
  120.                 if (i < 5) {
  121.  
  122.                     int level = worldIn.getBlockMetadata(x, y, z);
  123.  
  124.                     if (level == 15) {
  125.  
  126.                         worldIn.setBlock(x, y + 1, z, this);
  127.                         worldIn.setBlockMetadataWithNotify(x, y, z, 0, 4);
  128.  
  129.                     } else {
  130.  
  131.                         worldIn.setBlockMetadataWithNotify(x, y, z, level + 1, 4);
  132.  
  133.                     }
  134.                 }
  135.             }
  136.         }
  137.     }
  138.  
  139.     @Override
  140.     @SideOnly(Side.CLIENT)
  141.     public Item getItem(World world, int x, int y, int z) {
  142.         return MyItems.nori_leaf;
  143.     }
  144.  
  145.     @Override
  146.     public Item getItemDropped(int metadata, Random rand, int fortune) {
  147.         return MyItems.nori_leaf;
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment