Advertisement
Anagkai

transparency

Feb 3rd, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.30 KB | None | 0 0
  1. package anagkai.biodiversity.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import anagkai.biodiversity.Biodiversity;
  6. import anagkai.biodiversity.items.ItemsBiodiversity;
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.entity.item.EntityItem;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.init.Items;
  13. import net.minecraft.inventory.IInventory;
  14. import net.minecraft.item.ItemStack;
  15. import net.minecraft.tileentity.TileEntity;
  16. import net.minecraft.util.math.BlockPos;
  17. import net.minecraft.world.World;
  18.  
  19. public class BlockBiodiversityFishTrap extends Block{
  20.    
  21.     public BlockBiodiversityFishTrap(Material par1Material, String name) {
  22.         super(par1Material);
  23.         this.setUnlocalizedName(name);
  24.         this.setCreativeTab(Biodiversity.cTab);
  25.         this.setTickRandomly(true);
  26.     }
  27.  
  28.     /**
  29.      * Ticks the block if it's been scheduled
  30.      */
  31.     @Override
  32.     public void updateTick(World world, BlockPos pos, IBlockState state, Random random)
  33.     {
  34.         if ((world.getBlockState(pos.north()).getBlock() == Blocks.WATER) && (world.getBlockState(pos.south()).getBlock() == Blocks.WATER) && (world.getBlockState(pos.east()).getBlock() == Blocks.WATER) && (world.getBlockState(pos.west()).getBlock() == Blocks.WATER))
  35.         {
  36.             if(random.nextInt(7) == 0){
  37.                 TileEntity tileAbove = world.getTileEntity(pos.up());
  38.                 if(tileAbove instanceof IInventory) {
  39.                 IInventory inv = (IInventory) tileAbove;
  40.                 for(int i=0; i < inv.getSizeInventory(); i++) {
  41.                 if(inv.getStackInSlot(i) != null){
  42.                     if(inv.getStackInSlot(i).getItem() == Items.WHEAT_SEEDS || inv.getStackInSlot(i).getItem() == ItemsBiodiversity.saladSeeds ||
  43.                             inv.getStackInSlot(i).getItem() == ItemsBiodiversity.buckthornBerries) {
  44.                     inv.decrStackSize(i, 1);
  45.                     int ri;
  46.                     int rj;
  47.                     int di;
  48.                     int dj;
  49.                
  50.                     ri = random.nextInt(2);
  51.                     rj = random.nextInt(2);
  52.                
  53.                     di = pos.getX();
  54.                     dj = pos.getZ();
  55.                
  56.                     if (ri == 0){
  57.                         di++;}
  58.                     else{
  59.                         di--;}
  60.                     if (rj == 0){
  61.                         dj++;}
  62.                     else{
  63.                         dj--;}
  64.                
  65.                     ItemStack item1 = getItem(random);
  66.                     EntityItem entityitem1 = new EntityItem(world, di, pos.getY(), dj, item1);            
  67.                     world.spawnEntityInWorld(entityitem1);
  68.                     break;
  69.                     }}
  70.                 }
  71.                 }
  72.             }
  73.         }
  74.     }
  75.    
  76.     private ItemStack getItem(Random random) {
  77.         int randnumber = random.nextInt(200);
  78.         if(randnumber < 130){
  79.         return new ItemStack(Items.FISH, 1, 0);
  80.         }
  81.         if(randnumber >= 130 && randnumber < 170){
  82.             return new ItemStack(Items.FISH, 1, 1);
  83.             }
  84.         if(randnumber >= 170 && randnumber < 190){
  85.             return new ItemStack(Items.FISH, 1, 2);
  86.             }
  87.         if(randnumber >= 190 && randnumber < 197){
  88.             return new ItemStack(Items.FISH, 1, 3);
  89.             }
  90.         else{
  91.             return new ItemStack(ItemsBiodiversity.electricRay);
  92.         }
  93.     }
  94.  
  95.     @Override
  96.     public boolean isOpaqueCube(IBlockState state) {
  97.         return false;
  98.     }
  99.    
  100.     //public boolean renderAsNormalBlock() {
  101.     //  return false;
  102.     //}
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement