Solved Auto Smelt Help

Discussion in 'Plugin Development' started by andrewginn, Apr 6, 2016.

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

    Irantwomiles

    Theres really no reason to do one thing twice. All you have to do is check if the block you are mining is the block you want to be smelted, for example Iron ore, then you remove the drop and add one iron ingot to the players inventory, but make sure you check if the players inventory is full or not because it could possibly throw some errors.
     
  2. Offline

    andrewginn

    @CraftCreeper6 Something is wrong in the code, I just created a new project new classes, and new packages. Idk what it is.

    @Irantwomiles
    That is a good point but what if I wanted to add for instance gold ore. What would I do then?
     
  3. Offline

    Gonmarte

    Can you post your code again, and say again what is your problem?
     
  4. Offline

    mcdorli

    Please, read your code. Your switch doesn't do anything useful. It basically checks tge type of itemone, wich will always be iron_ore, id you don't understand, then learn more about switches.
     
  5. Offline

    andrewginn

    @mcdorli the switch is so it checks for the type of itemone and then looks for a case with the same id, it will then run the code which will then delete the iron ore from the inventory and give him the iron ingot, but it isn't working.

    @Gonmarte Here is the code
    Code:
    package me.xenless;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Auto extends JavaPlugin implements Listener {
    
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
        }
    
        @EventHandler
    
        public void onBlockBreak(BlockBreakEvent e) {
            ItemStack itemone = new ItemStack(Material.IRON_ORE);
            ItemStack itemtwo = new ItemStack(Material.IRON_INGOT);
            Player p = e.getPlayer();
            switch (itemone.getType()) {
            case IRON_BLOCK:
                p.getInventory().removeItem(itemone);
                p.getInventory().addItem(itemtwo);
                break;
            default:
                break;
            }
        }
    }
    Something is conflicting with it but this is the code that actually works look at my previous posts to see the broken one which includes blocks to inventory

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  6. Offline

    Gonmarte

    So its solved?
    Are you sure that code works? Test it and if so mark this as solved.
     
  7. Offline

    RenditionsRule

    It feels like it would help if you were looking for IRON_ORE in the switch statement, rather than IRON_BLOCK. This code will only run when you mine a block of iron.

    Also, rather than creating a new ItemStack that will always be iron ore, try creating an ItemStack that will get the Material from the block that was broken. That way, the switch statement might ACTUALLY work.
     
    Last edited: Apr 6, 2016
  8. Offline

    mcdorli

    Ok I say it the last time ITEMONE IS ALWAYS AN IRON ORE, YOU ALWAYS TRY TO REMOVE SOME IRON ORE FROM THE PLAYERS INVENTORY AND YOU ALWAYS GIVE HIM IRON INGOT, NO MATTER WHAT. CHECK FOR THE CURRENT ITEM.

    Don't think the API is the fault and not yohr code, that's not the case 99% of the times.

    I'm literally angry, because I posted this 3 TIMES

    Learn java please, it shpuld take at least a month and not 2 days.

    Btw, I'm not shouting, this is more readavle than bold.
     
    Last edited: Apr 6, 2016
  9. Offline

    andrewginn

Thread Status:
Not open for further replies.

Share This Page