@Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float par7,
      float par8,
      float par9) {
    int meta = world.getBlockMetadata(x, y, z);

    if (ToolHelper.isWrench(player.getCurrentEquippedItem()) && player.isSneaking()) {
      TileEntity tile = world.getTileEntity(x, y, z);

      if (tile != null && tile instanceof IWrenchable) {
        IWrenchable wrenchable = (IWrenchable) tile;

        wrenchable.setFacing(ToolHelper.getOppositeSide((short) side));
        return true;
      }
    } else {
      return super.onBlockActivated(world, x, y, z, player, side, par7, par8, par9);
    }

    return false;
  }
  @Override
  public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis) {
    if (axis == ForgeDirection.UNKNOWN) {
      return false;
    }
    TileEntity tileEntity = worldObj.getTileEntity(x, y, z);

    if ((tileEntity instanceof IWrenchable)) {
      IWrenchable te = (IWrenchable) tileEntity;

      int newFacing = ForgeDirection.getOrientation(te.getFacing()).getRotation(axis).ordinal();

      if (te.wrenchCanSetFacing(null, newFacing)) {
        te.setFacing((short) newFacing);
      }
    }

    return false;
  }
예제 #3
0
  public static boolean isWrenchClicked(TileEntity tileEntity, EntityPlayer player, int side) {
    if (player != null && tileEntity != null) {
      ItemStack equipped = player.getCurrentEquippedItem();

      if (equipped != null) {
        boolean ic2Wrench = IC2NuclearControl.instance.crossIC2.isWrench(equipped);
        boolean bcWrench =
            IC2NuclearControl.instance.crossBC.isWrench(equipped, tileEntity, player);
        if (player.isSneaking() && tileEntity instanceof IRotation) {
          if (ic2Wrench || bcWrench) {
            if (bcWrench) {
              IC2NuclearControl.instance.crossBC.useWrench(equipped, tileEntity, player);
            }

            if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
              ((IRotation) tileEntity).rotate();
            }
            return true;
          }
        } else if (bcWrench && tileEntity instanceof IWrenchable) {
          IWrenchable wrenchable = (IWrenchable) tileEntity;

          if (player.isSneaking()) {
            side += side % 2 * -2 + 1;
          }

          if (wrenchable.wrenchCanSetFacing(player, side)) {
            IC2NuclearControl.instance.crossBC.useWrench(equipped, tileEntity, player);
            if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
              wrenchable.setFacing((short) side);
            }
            return true;
          }
        }
      }
    }
    return false;
  }