Some Config help

Discussion in 'Plugin Development' started by SantaClawz69, Sep 6, 2017.

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

    SantaClawz69

    Hi, so I'm a really on and off programmer and sometimes I need refreshers on certain things. I just got back to programming from a long break and now I'm reviewing my code and I've set up a little project for myself that will integrate most of the basics. Right now I'm stuck on this config bit.

    So here it is, I'm trying to figure out how I could add certain block types into a config, if the block that was recently destroyed was in the config file, it would check what kind of item it was broken with. If it wasn't broken with the correct item then it would drop nothing, and if it was broken with the correct item it would drop something custom.

    I already know a method of doing this but it's just so inefficient and noobish, basically I can just use the BreakBlockEvent everytime a block breaks iterate through the config then use a whole bunch of else if statements to see what's in the players hand. But is there any other way of doing so?

    Also an important question can someone teach me or direct me to a resource for custom drops? So for example, I break a piece of wheat with a stone shovel it would drop 5 seeds and 5 wheat, or have a random number of wheat dropping? Thanks!
     
  2. Offline

    Zombie_Striker

    @SantaClawz69
    1. Create a HashMap. The keys will be the block types, and the values will be an Itemstack or Itemstack array (if you can have multiple correct items to mine with). This represents which blocks can be mined with which item
    2. In the onEnable, add all the materials and correct itemstacks into the map.
    3. On block break event.
    4. If the block's type is in the hashmap, and if the itemstack in the hashmap .isSimilar() to the item in the player's hand:
    5. Spawn a new itemstack (the drop) at the block's location.
    6. If it overrides the existing block drops, set setDroppedItems to false.
     
    SantaClawz69 likes this.
  3. Offline

    SantaClawz69

    Thank you, just got back from a trip I'll be trying out this method by tomorrow and will get back to you.

    Hi so I was looking over what you were saying and this is what I'm assuming I have to do
    First I'd probably make a list of ItemStacks, and Materials:
    List<Material> crops = new ArrayList<Material>();
    crops.add(The list of materials)

    List<ItemStack[]> items = new ArrayList<ItemStack[]>();
    items.add(The list of items)
    1.Create a hashmap" HashMap<Material, ItemStack[]> hash = new HashMap<Material, ItemStack[]>();
    2.In my onEnable: hash.put(crops, items);
    3. public void onBlockBreak(BlockBreakEvent e) {
    4. if(e.getBlock() == hash.keySet() && player.getItemInHand() == hash.values() ) {
    5. Not sure how to do


    Here is a list of the things that I want to do:
    • Non-Hoe
      • 0 items
    • Stone or Wood Hoe
      • 1 crop

      • 1 seed minimum
    • Iron or Gold Hoe
      • 2 crops

      • 1 seed minimum
    • Diamond Hoe
      • 3 crops

      • 1 seed minimum
    Please correct any of my code, I didn't do it in an IDE so somethings could be wrong or easily optimized.
    @Zombie_Striker @timtower
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited: Sep 24, 2017
Thread Status:
Not open for further replies.

Share This Page