Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.skcraft.creditvendor.CreditVendor;
- import com.skcraft.creditvendor.tileentity.TileEntityVendingMachine;
- import cpw.mods.fml.common.network.FMLNetworkHandler;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.world.World;
- public class BlockVendingMachine extends BlockContainer {
- public BlockVendingMachine( int id ) {
- super( id, Material.iron );
- setCreativeTab( CreditVendor.cVendorTab );
- setHardness( 0.6F );
- setResistance( 6000000.0F );
- setBlockUnbreakable();
- setStepSound( Block.soundMetalFootstep );
- }
- @Override
- public TileEntity createNewTileEntity( World world ) {
- return new TileEntityVendingMachine();
- }
- @Override
- public boolean onBlockActivated( World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ ) {
- if( !world.isRemote ) {
- FMLNetworkHandler.openGui( entityPlayer, CreditVendor.instance, 0, world, x, y, z );
- }
- return true;
- }
- @Override
- public void breakBlock( World world, int x, int y, int z, int id, int metadata ) {
- TileEntity tileEntity = world.getBlockTileEntity( x, y, z );
- if( tileEntity != null && tileEntity instanceof IInventory ) {
- IInventory inventory = ( IInventory )tileEntity;
- for( int slot = 0; slot < inventory.getSizeInventory(); slot++ ) {
- ItemStack stack = inventory.getStackInSlotOnClosing( slot );
- if( stack != null ) {
- float spawnX = x + world.rand.nextFloat();
- float spawnY = y + world.rand.nextFloat();
- float spawnZ = z + world.rand.nextFloat();
- EntityItem droppedItem = new EntityItem( world, spawnX, spawnY, spawnZ, stack );
- float multiple = 0.05F;
- droppedItem.motionX = ( -0.5F + world.rand.nextFloat() ) * multiple;
- droppedItem.motionY = ( 4F + world.rand.nextFloat() ) * multiple;
- droppedItem.motionZ = ( -0.5F + world.rand.nextFloat() ) * multiple;
- world.spawnEntityInWorld( droppedItem );
- }
- }
- }
- super.breakBlock( world, x, y, z, id, metadata );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement