Make inventory update like furnace

Discussion in 'Plugin Development' started by VortexGmer, May 25, 2015.

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

    VortexGmer

    Hi, I would like to do something inside a inventory while no one is looking inside. Also How do I put things into an inventory and keep them there so they don't get destroyed? So basically something like a furnace just it does something every few ticks.
     
  2. Offline

    mine-care

    @VortexGmer i made such a plugin where part of it had some destructive inventories where placed items would loze durability untill they eventually break.
    Anyway i had a inventory variable and a repeating task initialized onEnable and every 10 ticks it would go through all the items in the inventory and damage them (The inventory was a public class variable)
     
  3. Offline

    Zombie_Striker

    @VortexGmer Do what @mine-care suggested, but then look at the InventoryViewers.size() and see if its 0 (meaning no one is looking at it) If you want multiple inventories, then put the instance an Array of Inventories. To save it, put it in the config (config#set(PATH,the arraylist of inventories))
     
  4. Offline

    VortexGmer

    Inventory variable? What is that?
    And how would you check if it is the right inventory?
    @Zombie_Striker
    I' do not understand what you meant, the part where you say get viewers equals 0 I want it. To run with or without any of the viewers.
    Sorry for my typing, I am on a iPhone
     
  5. Offline

    mine-care

    @VortexGmer A variable of type "Inventory", why you want to check if it is the right one? the inventory will be held in a specific variable so there is no need to check if it is the proper one...

    @Zombie_Striker is right, as he proposed, if you want multyple inventories, hold them in an array or a list and every time the runnable runs loop through all the inventories and act as you would if it was just one :p
     
  6. Offline

    VortexGmer

    So basically for(Inventory i : solarpanels){
    if(i.contains(Battery/*Is a itemstack specified*\){
    //DO stuff?
    }
    }
     
  7. Offline

    mine-care

    @VortexGmer pretty mutch... Aso prefer "containsAtLeast" method to ignore/select the ammound that should bw contained.
     
  8. Offline

    VortexGmer

    don't understand
     
  9. Offline

    mine-care

    @VortexGmer i mean yes thats the way, but instead of using inventory.contains(...); use inventory.containsAtLeast(...,1);
     
  10. Offline

    VortexGmer

    Well, Is there any way to make the inventory only have one centered slot?
     
  11. Offline

    Just_Jitse

    @VortexGmer no that is not possible, unless you'ld use the Furnace UI.
    btw what you maybe could do is make a scheduler for the updating, I will be a ton of code but I guess it would work.
    I have at home something like that, I'll have a look when I have some time left ;)

    EDIT: maybe we can skype, then we can awnser question from eachother (my name is: Jitse13)
     
    Last edited: May 29, 2015
  12. Offline

    mine-care

  13. Offline

    Zombie_Striker

    Why has this not been done already?
    Code:
    Inventory inv = Bukkit.createInv(input);
    //or
    ArrayList<Inventory> invs = new ArrayList<Inventories>();
    
    public void onEnable(){
    getServer().getSchedular().scheduleSyncRepeatingTask(this,new Runnable(){
    
    public void run{
    for(Inventory theInv = invs){
    //this changes it for multiple inventories.
    theInvs.setItem(slot,itemchange);
    }
    //or to change a specific inventroy
    inv.setItem(slot,itemchange);
    }
    },0,20L);
    }
     
  14. Offline

    Just_Jitse

  15. Offline

    mine-care

    @Just_Jitse Oh well, not recomended :/ why having so many tasks spawned arround when you can simply have one with a loop?
     
  16. Offline

    Just_Jitse

    @mine-care That's also possible, maybe that'ld be better xD
     
Thread Status:
Not open for further replies.

Share This Page