MCPvP Salvage Plugin

Discussion in 'Plugin Development' started by LegitLanden, Jul 29, 2015.

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

    LegitLanden

    So I am trying to re-create the mcpvp salvage plugin and there just seems to be a problem for me. For example if I had a diamond chestplate in my hand and i left clicked a diamond block right next to a furnace I wouldnt know how to drop the amount of items based on the durability of the diamond chestplate. Let's say the durability of the chestplate was max, then it would drop 8 diamonds, if the durability was a little less than max, then it would drop 7. Would I have to hard code all of that?

    Here is what i have so far:


    @EventHandler

    public void onSalvage(PlayerInteractEvent e) {

    Player p = e.getPlayer();

    if (e.getAction() == Action.LEFT_CLICK_BLOCK) {

    if (e.getClickedBlock().getType() == Material.DIAMOND_BLOCK && e.getClickedBlock().getRelative(BlockFace.DOWN).getType() == Material.FURNACE || e.getClickedBlock().getRelative(BlockFace.SOUTH).getType() == Material.FURNACE || e.getClickedBlock().getRelative(BlockFace.UP).getType() == Material.FURNACE || e.getClickedBlock().getRelative(BlockFace.NORTH).getType() == Material.FURNACE || e.getClickedBlock().getRelative(BlockFace.WEST).getType() == Material.FURNACE || e.getClickedBlock().getRelative(BlockFace.EAST).getType() == Material.FURNACE) {

    if (p.getItemInHand().getType() == Material.DIAMOND_CHESTPLATE) {

    //drops diamonds based on the amount of durability of the diamond chestplate


    }
    }
    }
    }
     
  2. Offline

    farget92

  3. Offline

    Ruptur

    @LegitLanden
    Placing code inbetween [ code ] & [ /code ] (without the spaces) can help make the post clearer.

    A way would be dividing the max durability with 8 (ur max amount of diamonds u want to give out) . With tat information you should be able to give out the diamonds accordingly .

    You can get the max durability of the chestplate with material.getMaxDurability()
    Check the current durability with itemstack.getDurability().
     
  4. Offline

    LegitLanden

    Could you show me what that would look like?
     
  5. Offline

    mine-care

    @LegitLanden You need to turn the durability to X/8 (it will loose a lot of accuracy tho)
    i am not the math monstermind but i can think of:
    (currentDurability/MaxDurability * 8) and that would give you a value that is the ammount of diamonds you should give.
    For instance if the durability is 110/440 (just saying) then 110/440 * 8 = 2
     
Thread Status:
Not open for further replies.

Share This Page