Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package anagkai.biodiversity.blocks;
- import java.util.Random;
- import anagkai.biodiversity.Biodiversity;
- import anagkai.biodiversity.items.ItemsBiodiversity;
- import net.minecraft.block.Block;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.init.Blocks;
- import net.minecraft.init.Items;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.world.World;
- public class BlockBiodiversityFishTrap extends Block{
- public BlockBiodiversityFishTrap(Material par1Material, String name) {
- super(par1Material);
- this.setUnlocalizedName(name);
- this.setCreativeTab(Biodiversity.cTab);
- this.setTickRandomly(true);
- }
- /**
- * Ticks the block if it's been scheduled
- */
- @Override
- public void updateTick(World world, BlockPos pos, IBlockState state, Random random)
- {
- 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))
- {
- if(random.nextInt(7) == 0){
- TileEntity tileAbove = world.getTileEntity(pos.up());
- if(tileAbove instanceof IInventory) {
- IInventory inv = (IInventory) tileAbove;
- for(int i=0; i < inv.getSizeInventory(); i++) {
- if(inv.getStackInSlot(i) != null){
- if(inv.getStackInSlot(i).getItem() == Items.WHEAT_SEEDS || inv.getStackInSlot(i).getItem() == ItemsBiodiversity.saladSeeds ||
- inv.getStackInSlot(i).getItem() == ItemsBiodiversity.buckthornBerries) {
- inv.decrStackSize(i, 1);
- int ri;
- int rj;
- int di;
- int dj;
- ri = random.nextInt(2);
- rj = random.nextInt(2);
- di = pos.getX();
- dj = pos.getZ();
- if (ri == 0){
- di++;}
- else{
- di--;}
- if (rj == 0){
- dj++;}
- else{
- dj--;}
- ItemStack item1 = getItem(random);
- EntityItem entityitem1 = new EntityItem(world, di, pos.getY(), dj, item1);
- world.spawnEntityInWorld(entityitem1);
- break;
- }}
- }
- }
- }
- }
- }
- private ItemStack getItem(Random random) {
- int randnumber = random.nextInt(200);
- if(randnumber < 130){
- return new ItemStack(Items.FISH, 1, 0);
- }
- if(randnumber >= 130 && randnumber < 170){
- return new ItemStack(Items.FISH, 1, 1);
- }
- if(randnumber >= 170 && randnumber < 190){
- return new ItemStack(Items.FISH, 1, 2);
- }
- if(randnumber >= 190 && randnumber < 197){
- return new ItemStack(Items.FISH, 1, 3);
- }
- else{
- return new ItemStack(ItemsBiodiversity.electricRay);
- }
- }
- @Override
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- //public boolean renderAsNormalBlock() {
- // return false;
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement