Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

robot.suck() does not fire any event #900

Closed
ghost opened this issue Feb 8, 2015 · 3 comments
Closed

robot.suck() does not fire any event #900

ghost opened this issue Feb 8, 2015 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 8, 2015

Will be possible add some event to api when robot manipulate with containers in the map?

If on the server is some kind of protections, robot bypass all.

For example simulate playerinteract as robot owner will be fine. Then if simulation fail, cancel robot suck event.

@fnuecke
Copy link
Member

fnuecke commented Feb 9, 2015

OC uses inventories' isUseableByPlayer method to check if interaction is permissible. I'd have expected protection mods to hook into that, because, well, it's the standard API.

@ghost
Copy link
Author

ghost commented Feb 9, 2015

Thanks for suggestion, I will try it.

@ghost
Copy link
Author

ghost commented Mar 6, 2015

Im trying modify robot.suck, but event still not canceled:

InventoryWorldControl.scala

  @Callback
  def suck(context: Context, args: Arguments): Array[AnyRef] = {
    val facing = checkSideForAction(args, 0)
    val count = args.optionalItemCount(1)
    System.out.println("fakeplayer " + fakePlayer);
    if (InventoryUtils.inventoryAt(position.offset(facing)).exists(inventory => {
      inventory.isUseableByPlayer(fakePlayer) && InventoryUtils.extractFromInventory(InventoryUtils.insertIntoInventory(_, this.inventory, slots = Option(insertionSlots)), inventory, facing.getOpposite, count)
    })) {
      context.pause(Settings.get.suckDelay)
      val blockPos = position.offset(facing)
      val block = world.getBlock(blockPos)
      val metadata = world.getBlockMetadata(blockPos)
      System.out.println("blok " + position.offset(facing).x + " " + position.offset(facing).y + " " + position.offset(facing).z + " facing " + facing);
      System.out.println("robot " + position.x + " " + position.y + " " + position.z + " facing opposite " + facing.getOpposite);
      //val event = new PlayerInteractEvent(fakePlayer, PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK , position.offset(facing).x, position.offset(facing).y, position.offset(facing).z, 1, world)
      val event = new BlockEvent.BreakEvent(position.offset(facing).x, position.offset(facing).y, position.offset(facing).z, world, block, metadata, fakePlayer)
      MinecraftForge.EVENT_BUS.post(event)
      (event.isCanceled, "locked")
      //result(true)
      System.out.println("event canceled: " + event.isCanceled());
      result(!event.isCanceled())
    }
    else {
      for (entity <- suckableItems(facing) if !entity.isDead && entity.delayBeforeCanPickup <= 0) {
        val stack = entity.getEntityItem
        val size = stack.stackSize
        onSuckCollect(entity)
        if (stack.stackSize < size || entity.isDead) {
          context.pause(Settings.get.suckDelay)
          return result(true)
        }
      }
      result(false)
    }
  }

When use for example block break event in java, event is canceled when player cannot break block due protection plugin.

Working example from one of my mod (LaserHitsBlockEvent is from ic2 api):

           @SubscribeEvent
           public void onIC2LaserFire(LaserHitsBlockEvent laser) {
                   BreakEvent breakEv = new BreakEvent(laser.x, laser.y, laser.z, laser.world, null, 0, (EntityPlayer) laser.owner);
                   if (breakEv.isCanceled()) {
                           laser.setCanceled(true);
                   }

           }

If player cannot break block, laser event is canceled too. Similar way I would like use in th OC.
Im not familiar with scala, could you please help?

fnuecke added a commit that referenced this issue Mar 11, 2015
…ting with in-world inventories and in the inventory driver. See #900.

Hopefully doesn't break anything...
@fnuecke fnuecke closed this as completed Mar 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant