@SubscribeEvent
  public void onPlayerInteract0(PlayerInteractEvent event) {
    if (event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
      World world = event.world;
      EntityPlayer player = event.entityPlayer;
      int x = event.x;
      int y = event.y;
      int z = event.z;

      if (world == null || world.isRemote) return;
      if (player.isSneaking()) return;

      if (EtFuturum.enableEnchants) {
        TileEntityEnchantmentTable tile =
            Utils.getTileEntity(world, x, y, z, TileEntityEnchantmentTable.class);
        if (tile != null && world.getBlock(x, y, z) == Blocks.enchanting_table) {
          player.openGui(EtFuturum.instance, GUIsID.ENCHANTING_TABLE, world, x, y, z);
          event.setCanceled(true);
          return;
        }
      }

      if (EtFuturum.enableAnvil)
        if (world.getBlock(x, y, z) == Blocks.anvil) {
          player.openGui(EtFuturum.instance, GUIsID.ANVIL, world, x, y, z);
          event.setCanceled(true);
          return;
        }
    }
  }
 @SubscribeEvent
 public void onChocopediaRightClick(PlayerInteractEvent event) {
   if (event.action == Action.RIGHT_CLICK_AIR) {
     if (event.entity instanceof EntityPlayer) {
       EntityPlayer player = (EntityPlayer) event.entity;
       ItemStack currentItem = player.getCurrentEquippedItem();
       if (currentItem != null) {
         if (currentItem.getItem().equals(ChocoCraftItems.chocopediaItem)) {
           GuiStarter.startChocopediaGui(null);
           if (event.isCancelable()) {
             event.setCanceled(true);
           }
         }
       }
     }
   }
 }
Beispiel #3
0
 @SubscribeEvent(priority = EventPriority.LOW)
 public void playerInteract(PlayerInteractEvent event) {
   if (event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.worldObj.isRemote) {
     if (placing.get() != null) return; // for mods that do dumb stuff and call this event like MFR
     placing.set(event);
     if (place(event.entityPlayer, event.entityPlayer.worldObj)) event.setCanceled(true);
     placing.set(null);
   }
 }
 @SubscribeEvent(priority = EventPriority.HIGHEST)
 public void buildWorktables(PlayerInteractEvent evt) {
   if (evt.action == Action.RIGHT_CLICK_BLOCK) {
     Block b = evt.world.getBlock(evt.x, evt.y, evt.z);
     if (b == Blocks.crafting_table
         || b instanceof BlockWorkbench
         || TinkerToolHandler.getInstance().isWorkbench(b)) {
       if (this.checkAndBuildWorktable(evt.world, evt.x, evt.y, evt.z)) evt.setCanceled(true);
     }
   }
 }
  @SubscribeEvent
  public void onBlockClick(PlayerInteractEvent e) {
    if (!e.world.isRemote) {
      if (e.action == Action.RIGHT_CLICK_BLOCK
          && CmdDumpBlockData.getWaitForBlockClick(e.entityPlayer.getUniqueID())) {
        StringBuilder sb = new StringBuilder();
        Block blc = e.world.getBlock(e.x, e.y, e.z);
        if (blc == null) {
          return;
        }

        int meta = e.world.getBlockMetadata(e.x, e.y, e.z);

        sb.append(
            "BlockID: "
                + GameData.getBlockRegistry().getNameForObject(blc)
                + "("
                + GameData.getBlockRegistry().getIDForObject(blc)
                + ")\n");
        sb.append(
            "Block name: " + blc.getUnlocalizedName() + " = " + blc.getLocalizedName() + "\n");
        sb.append("XYZ: " + e.x + " " + e.y + " " + e.z + "\n");
        sb.append("Metadata: " + meta + "\n");
        sb.append(
            "Lightlevel: "
                + "block: "
                + e.world.getSavedLightValue(EnumSkyBlock.Block, e.x, e.y, e.z)
                + ", sky: "
                + e.world.getSavedLightValue(EnumSkyBlock.Sky, e.x, e.y, e.z)
                + "\n");
        if (blc.hasTileEntity(meta)) {
          TileEntity te = e.world.getTileEntity(e.x, e.y, e.z);
          if (te != null) {
            NBTTagCompound nbt = new NBTTagCompound();
            te.writeToNBT(nbt);
            sb.append("NBT: {" + CmdDumpItemData.getNBTString(nbt, 1) + "}");
          }
        }

        System.out.println("\n" + sb.toString());

        e.setCanceled(true);
      }
    }
  }
Beispiel #6
0
 @SubscribeEvent
 public void interactEvent(PlayerInteractEvent event) {
   IPokemob pokemob = proxy.getPokemob(event.entityPlayer);
   if (pokemob == null) return;
   EntityPlayer player = event.entityPlayer;
   if (event.entityPlayer.getHeldItem() != null
       && event.entityPlayer.isSneaking()
       && event.entityPlayer.getHeldItem().getItem() instanceof ItemPokedex) {
     pokemob.getPokemobInventory().func_110134_a((IInvBasic) pokemob);
     if (!event.world.isRemote) {
       event.setCanceled(true);
       event.entityPlayer.openGui(
           PokePlayer.INSTANCE, Proxy.POKEMOBGUI, event.entityPlayer.worldObj, 0, 0, 0);
     }
   } else if (event.action == Action.RIGHT_CLICK_AIR && event.entityPlayer.getHeldItem() != null) {
     ((Entity) pokemob).interactFirst(player);
     proxy.getMap().get(event.entityPlayer.getUniqueID()).save(player);
   }
 }
 @SubscribeEvent
 public void handleCropRightClick(PlayerInteractEvent event) {
   int x = event.x, y = event.y, z = event.z;
   Block block = event.world.getBlock(x, y, z);
   int meta = event.world.getBlockMetadata(x, y, z);
   if (ConfigHandler.allowCropRC
       && event.action == Action.RIGHT_CLICK_BLOCK
       && (event.entityPlayer.getHeldItem() == null || !event.entityPlayer.isSneaking())) {
     for (PlantInfo info : plants) {
       if (info.blockInst == block && meta == info.meta) {
         if (event.world.isRemote) {
           event.entityPlayer.swingItem();
         } else {
           currentPlant = info;
           block.dropBlockAsItem(event.world, x, y, z, meta, 0);
           currentPlant = null;
           event.world.setBlockMetadataWithNotify(x, y, z, info.resetMeta, 3);
           event.setCanceled(true);
         }
         break;
       }
     }
   }
 }
  @SubscribeEvent
  /**
   * Used to store side clicked and also forces onBlockActivated event when entityPlayer is sneaking
   * and activates block with the Carpenter's Hammer.
   */
  public void onPlayerInteractEvent(PlayerInteractEvent event) {
    if (event.entityPlayer.worldObj.isRemote || event.isCanceled()) {
      return;
    }

    Block block = event.entity.worldObj.getBlock(event.x, event.y, event.z);

    if (block instanceof BlockCoverable) {

      eventFace = event.face;
      eventEntityPlayer = event.entityPlayer;

      ItemStack itemStack = eventEntityPlayer.getHeldItem();

      MovingObjectPosition object =
          getMovingObjectPositionFromPlayer(eventEntityPlayer.worldObj, eventEntityPlayer);

      if (object != null) {
        hitX = (float) object.hitVec.xCoord - event.x;
        hitY = (float) object.hitVec.yCoord - event.y;
        hitZ = (float) object.hitVec.zCoord - event.z;
      } else {
        hitX = hitY = hitZ = 1.0F;
      }

      switch (event.action) {
        case LEFT_CLICK_BLOCK:
          boolean toolEquipped =
              itemStack != null
                  && (itemStack.getItem() instanceof ICarpentersHammer
                      || itemStack.getItem() instanceof ICarpentersChisel);

          /*
           * Creative mode doesn't normally invoke onBlockClicked(), but rather it tries
           * to destroy the block.
           *
           * We'll invoke it here when a Carpenter's tool is being held.
           */

          if (toolEquipped && eventEntityPlayer.capabilities.isCreativeMode) {
            block.onBlockClicked(
                eventEntityPlayer.worldObj, event.x, event.y, event.z, eventEntityPlayer);
          }

          break;
        case RIGHT_CLICK_BLOCK:

          /*
           * Make sure sneak right-click makes it through the onBlockActivate.
           */

          if (eventEntityPlayer.isSneaking()
              && !(itemStack != null
                  && itemStack.getItem() instanceof ItemBlock
                  && !BlockProperties.isOverlay(itemStack))) {
            block.onBlockActivated(
                eventEntityPlayer.worldObj,
                event.x,
                event.y,
                event.z,
                eventEntityPlayer,
                event.face,
                1.0F,
                1.0F,
                1.0F);
          }

          break;
        default:
          {
          }
      }
    }
  }