Get inventory of a hopper minecart and drop it

Discussion in 'Plugin Development' started by MarioG1, Sep 5, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    MarioG1

    I am trying to write a simple plugin/add-on for lockette that protects locked chest from Hopper Minecarts.

    How the plugin should work:
    Deny placing of hopper minecarts on rail under locked chests: WORKING
    Remove the hopper minecart if it drives under a locked chest: WORKING

    But now a have a problem. The inventory of the hopper minecart should be dropped when it gets removed but i have no idea how this is working.

    Code:java
    1. @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
    2. public void onVehicleMove(final VehicleMoveEvent event){
    3. if(event.getVehicle().getType() == EntityType.MINECART_HOPPER)
    4. {
    5. final Block ref=event.getTo().getBlock().getRelative(BlockFace.UP);
    6. if (!shouldCheck(ref));
    7. if (Lockette.isProtected(ref))
    8. {
    9. getLogger().log(Level.INFO,"Block:"+event.getTo().getBlock().getRelative(BlockFace.UP).getType());
    10. event.getVehicle().remove();
    11. ItemStack drop = new ItemStack(Material.HOPPER_MINECART, 1);
    12. World world = event.getVehicle().getWorld();
    13. world.dropItem(event.getTo(), drop);
    14. // Drop also the Inventory of the Hopper Minecart
    15. }
    16. }
    17.  
    18. }
     
Thread Status:
Not open for further replies.

Share This Page