Ejemplo n.º 1
0
  @Override
  public ArrayList<ItemStack> harvestPlant(
      Point3I point, Block plantBlock, int metadata, World worldObj) {
    PlayerFake faker = new PlayerFake((WorldServer) worldObj);
    plantBlock.onBlockActivated(
        worldObj, point.getX(), point.getY(), point.getZ(), faker, metadata, 0, 0, 0);

    AxisAlignedBB block =
        AxisAlignedBB.getBoundingBox(
            point.getX(),
            point.getY(),
            point.getZ(),
            point.getX() + 1,
            point.getY() + 1,
            point.getZ() + 1);
    List<EntityItem> entities = worldObj.getEntitiesWithinAABB(EntityItem.class, block);
    if (entities.isEmpty()) {
      return null;
    }
    ArrayList<ItemStack> items = new ArrayList<ItemStack>();
    for (EntityItem item : entities) {
      items.add(item.getEntityItem());
      worldObj.removeEntity(item);
    }

    return items;
  }
 public void activate(Vector3f pos) {
   if (_world.blockExists((int) pos.getX(), (int) pos.getY(), (int) pos.getZ())) {
     Block blk =
         Block.blocksList[_world.getBlockId((int) pos.getX(), (int) pos.getY(), (int) pos.getZ())];
     blk.onBlockActivated(
         _world, (int) pos.getX(), (int) pos.getY(), (int) pos.getZ(), _player, 0, 0, 0, 0);
   }
 }
Ejemplo n.º 3
0
 @Override
 public boolean placeSeed(World worldObj, ItemStack itemStack, Point3I point, boolean doAction) {
   int metaData = worldObj.getBlockMetadata(point.getX(), point.getY(), point.getZ());
   Block actualBlock = worldObj.getBlock(point.getX(), point.getY(), point.getZ());
   if (actualBlock != null) {
     if (doAction) {
       PlayerFake faker = new PlayerFake((WorldServer) worldObj);
       faker.inventory.setInventorySlotContents(1, itemStack.copy());
       faker.setItemInHand(1);
       faker.setPosition(point.getX(), point.getY(), point.getZ());
       actualBlock.onBlockActivated(
           worldObj, point.getX(), point.getY(), point.getZ(), faker, metaData, 0, 0, 0);
       if ((faker.inventory.getStackInSlot(1) != null)
           && (faker.inventory.getStackInSlot(1).stackSize == itemStack.stackSize)) {
         faker = null;
         return false;
       }
       faker = null;
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 4
0
  @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:
          {
          }
      }
    }
  }
Ejemplo n.º 5
0
  public static boolean place(EntityPlayer player, World world) {
    MovingObjectPosition hit = RayTracer.reTrace(world, player);
    if (hit == null) return false;

    BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ).offset(hit.sideHit);
    ItemStack held = player.getHeldItem();
    McBlockPart part = null;
    if (held == null) return false;

    Block heldBlock = Block.getBlockFromItem(held.getItem());
    if (heldBlock == Blocks.air) return false;

    if (heldBlock == XYreloaded.blockWire) part = new WirePart();

    if (part == null) return false;

    if (world.isRemote
        && !player
            .isSneaking()) // attempt to use block activated like normal and tell the server the
    // right stuff
    {
      Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
      Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ);
      if (!ignoreActivate(block)
          && block.onBlockActivated(
              world,
              hit.blockX,
              hit.blockY,
              hit.blockZ,
              player,
              hit.sideHit,
              (float) f.x,
              (float) f.y,
              (float) f.z)) {
        player.swingItem();
        PacketCustom.sendToServer(
            new C08PacketPlayerBlockPlacement(
                hit.blockX,
                hit.blockY,
                hit.blockZ,
                hit.sideHit,
                player.inventory.getCurrentItem(),
                (float) f.x,
                (float) f.y,
                (float) f.z));
        return true;
      }
    }

    TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
    if (tile == null || !tile.canAddPart(part)) return false;

    if (!world.isRemote) {
      TileMultipart.addPart(world, pos, part);
      world.playSoundEffect(
          pos.x + 0.5,
          pos.y + 0.5,
          pos.z + 0.5,
          part.getBlock().stepSound.func_150496_b(),
          (part.getBlock().stepSound.getVolume() + 1.0F) / 2.0F,
          part.getBlock().stepSound.getPitch() * 0.8F);
      if (!player.capabilities.isCreativeMode) {
        held.stackSize--;
        if (held.stackSize == 0) {
          player.inventory.mainInventory[player.inventory.currentItem] = null;
          MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
        }
      }
    } else {
      player.swingItem();
      new PacketCustom(PacketHandler.channel, 1).sendToServer();
    }
    return true;
  }