Package vazkii.botania.common.block.dispenser

Source Code of vazkii.botania.common.block.dispenser.BehaviourSeeds

/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [May 16, 2014, 10:36:05 PM (GMT)]
*/
package vazkii.botania.common.block.dispenser;

import net.minecraft.block.Block;
import net.minecraft.block.BlockDispenser;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;

public class BehaviourSeeds extends BehaviorDefaultDispenseItem {

  Block block;

  public BehaviourSeeds(Block block) {
    this.block = block;
  }

  @Override
  public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) {
    EnumFacing facing = BlockDispenser.func_149937_b(par1IBlockSource.getBlockMetadata());
    int x = par1IBlockSource.getXInt() + facing.getFrontOffsetX();
    int y = par1IBlockSource.getYInt() + facing.getFrontOffsetY();
    int z = par1IBlockSource.getZInt() + facing.getFrontOffsetZ();
    World world = par1IBlockSource.getWorld();

    if(world.getBlock(x, y, z).isAir(world, x, y, z) && block.canBlockStay(world, x, y, z)) {
      world.setBlock(x, y, z, block);
      par2ItemStack.stackSize--;
      return par2ItemStack;
    }

    return super.dispenseStack(par1IBlockSource, par2ItemStack);
  }

}
TOP

Related Classes of vazkii.botania.common.block.dispenser.BehaviourSeeds

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.