Solved Iron Ore > Iron Ingot

Discussion in 'Plugin Development' started by HeadGam3z, Jun 4, 2014.

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

    HeadGam3z

    I'm trying to use a BlockPlaceEvent for when a player places an ore, it breaks naturally (breakNaturally()) and it's been going pretty good until I got to Iron Ore and Gold Ore.

    My problem is, when I use breakNaturally(), it just breaks into it's self again (the ore), but I want it to break into an ingot instead.

    Is there some sort of method for this? I've done some research and saw nothing, but I thought maybe you guys would have an answer. Thanks!
     
  2. Offline

    Adriani6

    How about cancel the event and spawn iron ingot in place ? Just my thought.
     
  3. Offline

    Kassestral

    HeadGam3z
    Possibly something like this?
    Code:java
    1. @EventHandler
    2. public void onOreplace(BlockPlaceEvent e){
    3. Material block = e.getBlock().getType();
    4.  
    5. if(block.equals(Material.IRON_ORE)){
    6. e.getBlock().getDrops().clear();
    7. e.getBlock().getDrops().add(new ItemStack(Material.IRON_INGOT));
    8. e.getBlock().breakNaturally();
    9. }
    10. if(block.equals(Material.GOLD_ORE)){
    11. e.getBlock().getDrops().clear();
    12. e.getBlock().getDrops().add(new ItemStack(Material.GOLD_INGOT));
    13. e.getBlock().breakNaturally();
    14. }
    15. }
     
  4. Offline

    HeadGam3z

    Adriani6 Kassestral
    Yes, I have tried something like that, and it didn't seem to cancel the drops nor spawn the item. I'm thinking because that's mainly for BlockBreakEvent, not BlockPlaceEvent; but I could be wrong.

    Here's what I've tried:
    Code:java
    1. if (e.getBlock().getType().equals(Material.IRON_ORE)) {
    2. e.getBlock().breakNaturally();
    3. e.getBlock().getDrops().remove(Material.IRON_ORE);
    4. e.getBlock().getDrops().add(new ItemStack(Material.IRON_INGOT));
    5. }

    (like what Kassestral suggested)
    But no bananas.
     
  5. Offline

    Kassestral

    In the code you tried, your breaking the iron ore, before changing the drops :D you need to first change the drops, then break it naturally
     
  6. Offline

    HeadGam3z

    Kassestral
    I see what you mean, so I reversed them and tested it. But it still didn't work. It seems like it's ignoring the remove and add methods, and just breaking the block. Bit of a honey badger this error is...
     
  7. Offline

    Kassestral

    Give me like 5 minutes to test some methods of sorting tho out :)
     
  8. Offline

    HeadGam3z

    Kassestral
    Okay, I'm testing out a few as well, so you're not alone ;D
     
  9. Offline

    Kassestral

    HeadGam3z
    Here this works, I tested
    Code:java
    1. @EventHandler
    2. public void onOreplace(BlockPlaceEvent e){
    3. Player p = e.getPlayer();
    4. Material block = e.getBlock().getType();
    5. Location l = e.getBlock().getLocation();
    6.  
    7. if(block.equals(Material.IRON_ORE)){
    8. p.getWorld().getBlockAt(l).setType(Material.AIR);
    9. p.getWorld().dropItemNaturally(l, new ItemStack(Material.IRON_INGOT));
    10. }
    11. if(block.equals(Material.GOLD_ORE)){
    12. p.getWorld().getBlockAt(l).setType(Material.AIR);
    13. p.getWorld().dropItemNaturally(l, new ItemStack(Material.GOLD_INGOT));
    14. }
    15. }
     
    HeadGam3z likes this.
  10. Offline

    HeadGam3z

    Kassestral
    Good stuff, don't know why I didn't think of that.
    Thanks!
     
  11. Offline

    Kassestral

    HeadGam3z
    Haha no problem :)
     
Thread Status:
Not open for further replies.

Share This Page