Java 类net.minecraft.block.BlockDropper 实例源码

项目:CustomWorldGen    文件:VanillaInventoryCodeHooks.java   
public static boolean dropperInsertHook(World world, BlockPos pos, TileEntityDispenser dropper, int slot, ItemStack stack)
{
    EnumFacing enumfacing = world.getBlockState(pos).getValue(BlockDropper.FACING);
    BlockPos offsetPos = pos.offset(enumfacing);
    TileEntity tileEntity = world.getTileEntity(offsetPos);
    if (tileEntity == null)
        return true;
    if (!tileEntity.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, enumfacing.getOpposite()))
        return true;

    IItemHandler capability = tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, enumfacing.getOpposite());

    ItemStack result = ItemHandlerHelper.insertItem(capability, ItemHandlerHelper.copyStackWithSize(stack, 1), false);

    if (result == null)
    {
        result = stack.copy();

        if (--result.stackSize == 0)
        {
            result = null;
        }
    }
    else
    {
        result = stack.copy();
    }
    dropper.setInventorySlotContents(slot, result);
    dropper.markDirty();
    return false;
}
项目:minecraft-roguelike    文件:Dropper.java   
public boolean generate(IWorldEditor editor, Cardinal dir, Coord pos){

        MetaBlock container = new MetaBlock(Blocks.DROPPER);
        container.withProperty(BlockDropper.FACING, Cardinal.facing(dir));
        container.set(editor, pos);
        return true;
    }
项目:TaleCraft    文件:Invoke.java   
public static final void trigger(World world, BlockPos position, IBlockState state, EnumTriggerState state2) {
    Block block = state.getBlock();

    if(block instanceof TCITriggerableBlock){
        ((TCITriggerableBlock) state.getBlock()).trigger(world, position, state2);
        return;
    }

    if(block instanceof BlockCommandBlock) {
        ((TileEntityCommandBlock)world.getTileEntity(position)).getCommandBlockLogic().trigger(world);
        return;
    }

    // Just for the heck of it!
    if(block instanceof BlockTNT) {
        ((BlockTNT) block).explode(world, position, state.withProperty(BlockTNT.EXPLODE, Boolean.TRUE), null);
        world.setBlockToAir(position);
        return;
    }

    if(block instanceof BlockDispenser) {
        block.updateTick(world, position, state, TaleCraft.random);
        return;
    }

    if(block instanceof BlockDropper) {
        block.updateTick(world, position, state, TaleCraft.random);
        return;
    }

    // XXX: Experimental: This could break with any update.
    if(block instanceof BlockLever) {
        state = state.cycleProperty(BlockLever.POWERED);
        world.setBlockState(position, state, 3);
        world.playSound(position.getX() + 0.5D, position.getY() + 0.5D, position.getZ() + 0.5D, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 0.3F, state.getValue(BlockLever.POWERED).booleanValue() ? 0.6F : 0.5F, false);
        world.notifyNeighborsOfStateChange(position, block, true);
        EnumFacing enumfacing1 = state.getValue(BlockLever.FACING).getFacing();
        world.notifyNeighborsOfStateChange(position.offset(enumfacing1.getOpposite()), block, true);
        return;
    }

    // XXX: Experimental: This could break with any update.
    if(block instanceof BlockButton) {
        world.setBlockState(position, state.withProperty(BlockButton.POWERED, Boolean.valueOf(true)), 3);
        world.markBlockRangeForRenderUpdate(position, position);
        world.playSound(position.getX() + 0.5D, position.getY() + 0.5D, position.getZ() + 0.5D, SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON, SoundCategory.BLOCKS, 0.3F, 0.6F, false); //TODO There are multiple button click sounds
        world.notifyNeighborsOfStateChange(position, block, true);
        world.notifyNeighborsOfStateChange(position.offset(state.getValue(BlockDirectional.FACING).getOpposite()), block, true);
        world.scheduleUpdate(position, block, block.tickRate(world));
    }

    // XXX: Implement more vanilla triggers?
}