How would i insert a item into a place chest?

Discussion in 'Plugin Development' started by AdvsNoob, Jan 12, 2012.

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

    AdvsNoob

    I've been messing around with this for a while now and i cant seem to figure it out.

    I want to place stuff into chest that are located in Abandon Mine Shafts but i am not quite sure how to begin this.

    What i am basically saying how would i go forth getting all the chests in a certain biome (I think Abandon Mine Shafts are there own biome) and adding (updating) a item to that chest.

    I do know Java but i am rarely new to programming plugins. So can i get some examples please? :]
     
  2. Offline

    wwsean08

    you would have to go block by block and check if each block is a chest, then from their you get it's inventory, and add the item(s). However as for an example i'll let others do that if they choose to. But that's the general process you will have to do.
     
  3. Offline

    AdvsNoob

    Well my initial plan was to use the PlayerInteractEvent to get the block and then compare the ID to see if its a chest.
    But now i that i got that down i need to find out how to add an item into the chest it self.
     
  4. Offline

    wwsean08

    ah ok well thats different than your description (the part about getting all the chests in the biome). Heres roughly how you would do it. You would check the block (or the block's state, I can never remember, someone can fill that part in), if it is a chest then you will be able to cast the block as a chest. From there once it's a chest you will be able to get it's inventories (since chests have inventories), and once you get it's inventory you can add the items with a simple method call
     
  5. Offline

    Zacherl

    Before adding an item, you have to check whether the chest was placed by a player or by the world generator. You could do that by logging all player placed chests to a database for example.
     
  6. Offline

    AdvsNoob

    May i see some example code and methods please? Like i said im new to using bukkit jar
     
  7. Offline

    Karl Marx

    IIRC, there are no biomes for structures, including mineshafts. Since biomes do not change across the y axis, that would mean that everything above and below the mineshaft would also be considered a mineshaft, biome-wise; so it wouldn't help you much anyways.

    If there is indeed an easy way to determine if a chest was placed or generated that might work well enough. You'd have to either scan every block in the game (very resource intensive) or else track which chests have been opened before, to prevent item duplication. You'd also still have a problem with naturally occurring chests in fortresses and dungeons though, if you care about those.

    It'd be slightly better if you tapped into the mineshaft generator code and got your chest locations from there, but you'd still have a problem with old maps not matching the code after an update, and you'd still have to store which chests have already been modified.

    Really, your best bet is just to modify the mineshaft generating code to just add the items you want on chunk generation.
     
Thread Status:
Not open for further replies.

Share This Page