Java 类net.minecraft.block.BlockDoor.EnumDoorHalf 实例源码

项目:Kingdom-Keys-Re-Coded    文件:ItemKeyblade.java   
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (player.getHeldItemMainhand().getItem() == ModItems.WoodenKeyblade || player.getHeldItemMainhand().getItem() == ModItems.WoodenStick || player.getHeldItemMainhand().getItem() == ModItems.DreamSword)
        return EnumActionResult.PASS;

    if (world.getBlockState(pos).getBlock() instanceof BlockDoor) {
        SoundEvent sound;
        PlayerStatsCapability.IPlayerStats STATS = player.getCapability(ModCapabilities.PLAYER_STATS, null);
        if ((!STATS.getRecharge()) || player.getCapability(ModCapabilities.CHEAT_MODE, null).getCheatMode())
        {
            if (world.getBlockState(pos).getValue(BlockDoor.HALF) == EnumDoorHalf.UPPER)
            {
                world.setBlockState(pos.down(), world.getBlockState(pos.down()).withProperty(BlockDoor.OPEN, !world.getBlockState(pos.down()).getValue(BlockDoor.OPEN)));
                sound = world.getBlockState(pos.down()).getValue(BlockDoor.OPEN) ? SoundEvents.BLOCK_IRON_DOOR_CLOSE : SoundEvents.BLOCK_IRON_DOOR_OPEN;
                world.playSound(player, pos, sound, SoundCategory.BLOCKS, 1.0f, 1.0f);
                return EnumActionResult.SUCCESS;
            } else {
                world.setBlockState(pos, world.getBlockState(pos).withProperty(BlockDoor.OPEN, !world.getBlockState(pos).getValue(BlockDoor.OPEN)));
                sound = world.getBlockState(pos).getValue(BlockDoor.OPEN) ? SoundEvents.BLOCK_IRON_DOOR_CLOSE : SoundEvents.BLOCK_IRON_DOOR_OPEN;
                world.playSound(player, pos, sound, SoundCategory.BLOCKS, 1.0f, 1.0f);
                return EnumActionResult.SUCCESS;
            }
        }
    }
    return super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
}
项目:EnderIO    文件:ItemYetaWrench.java   
@Override
public @Nonnull EnumActionResult onItemUseFirst(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side,
    float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) {

  if (world.isRemote) {
    // If its client side we have to return pass so this method is called on server, where we need to perform the op
    return EnumActionResult.PASS;
  }

  final IBlockState blockState = world.getBlockState(pos);
  IBlockState bs = blockState;
  Block block = bs.getBlock();
  boolean ret = false;
  RightClickBlock e = new RightClickBlock(player, hand, pos, side, new Vec3d(hitX, hitY, hitZ));
  if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.getUseBlock() == Result.DENY || e.getUseItem() == Result.DENY) {
    return EnumActionResult.PASS;
  }
  if (block instanceof BlockDoor) {
    EnumDoorHalf half = bs.getValue(BlockDoor.HALF);
    if (half == EnumDoorHalf.UPPER) {
      pos = pos.down();
    }
  }
  if (!player.isSneaking() && block.rotateBlock(world, pos, side)) {
    ret = true;
  } else if (block instanceof IBlockPaintableBlock && !player.isSneaking() && !YetaUtil.shouldHeldItemHideFacades(player)) {
    IBlockState paintSource = ((IBlockPaintableBlock) block).getPaintSource(blockState, world, pos);
    if (paintSource != null) {
      final IBlockState rotatedPaintSource = PaintUtil.rotate(paintSource);
      if (rotatedPaintSource != paintSource) {
        ((IBlockPaintableBlock) block).setPaintSource(blockState, world, pos, rotatedPaintSource);
      }
      ret = true;
    }
  }

  // Need to catch 'shift-clicks' here and pass them on manually or an item in the off hand can eat the right click
  // so 'onBlockActivated' is never called
  if (!ret && player.isSneaking() && block instanceof BlockEio<?>) {
    BlockEio<?> beio = (BlockEio<?>) block;
    if (beio.shouldWrench(world, pos, player, side)) {
      beio.onBlockActivated(world, pos, bs, player, hand, side, hitX, hitY, hitZ);
      ret = true;
    }
  }
  if (ret) {
    player.swingArm(hand);
  }
  return ret ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}