7

I am using the following Command to spawn a new chest at the given coordinates with stuff in it at each new round:

/setblock 264 4 997 minecraft:chest 0 replace {Items:[{id:274,Count:1,Slot:0},{id:275,Count:1,Slot:1}]}

The problem with that is that when replacing the old chest all the stuff in the old chest is thrown out. And that's pretty much not what I want. I need to find a way to replace a chest which might have stuff in it without throwing those things out.

Someone else said I should replace the given position for one tick with lava, which I tried. Works in 90% of the tries (in the other 10% the items from the chest are thrown to far away - out of the spawned lava block), but the problem with that is that I can't use it in wooden areas because it might burn everything down.

So what can I do to fix that problem, because otherwise my custom made Pv.P map is not gonna work?

Thanks very much!

  • 2
    Not exactly sure, but I think you want to use destroy instead of replace – MBraedley Nov 17 '13 at 21:05
  • 1
    @MBraedley I just tested it, destroying a chest has the same effect. – Unionhawk Nov 17 '13 at 21:14
  • 1
    This is very strange. Even a temporary /gamerule doTileDrops false doesn't work. – Unionhawk Nov 17 '13 at 21:18
  • 1
    I have this nagging feeling that SethBling figured it out, and I thought it was with destroy. – MBraedley Nov 17 '13 at 21:19
  • 1
    Yep, its very strange. I THINK destroy is meant to do what i described in my question and replace SHOULD do what i asked for in this question. I guess it's a bug? – Shiuyin Nov 17 '13 at 21:31
3

As of the latest, latest snapshot (14w02b), this is most certainly possible. In fact, there's an easier way to do the whole thing now, which is awesome. With the /blockdata command added in the snapshot, you can modify and overwrite the contents of a tile entity (including a chest), and much, much more. The applications of /blockdata go beyond what I can fully comprehend at this point in time, but, for this specific case, it's not too hard.

Let's say for example your equipment chest is supposed to contain a notch apple, a gold sword, a bow, and a stack of arrows. The command for that would be /blockdata X Y Z {Items:[{id:322,Damage:1,Count:1,Slot:0},{id:283,Count:1,Slot:1},{id:261,Count:1,Slot:2},{id:262,Count:64,Slot:3}]}, replacing X Y and Z as appropriate. There's a lot of stuff going on in that command, but essentially, you are changing the data of the chest to contain the specified items. It's the same concept as using /setblock to spawn a new chest with these items, except instead of replacing the chest, you're overwriting its data.

In this more specific case, you want /blockdata 264 4 997 {Items:[{id:274,Count:1,Slot:0},{id:275,Count:1,Slot:1}]}.

And, of course, if you want an empty chest, all you need to do is use /blockdata X Y Z {Items:[]}

  • 1
    But this would also overwrite any items still in the chest no? If you use this command when there is already something in slot 0 for example, would the item in slot 0 not be replaced by your new item? OP wants it to not be replaced. – hammythepig Mar 11 '14 at 5:08
  • 1
    @hammythepig I'm looking at what the OP wants to do. What they want to do is reset a bunch of chests at the end of a game. Before, this was possible, but made a mess of items everywhere. This method can be used to clear items (/blockdata X Y Z {Items:[]}) to make way for the old method, or, it can replace the old method entirely, and accomplish the whole task in one go. The confusion might come from "not throwing those things out"; that means that he wants a way of replacing chests without having the old contents dropping on the floor. – Unionhawk Mar 11 '14 at 14:06
  • 1
    Ah correct, I read OP wrong. I thought he wanted to keep the stuff in the chest but he merely didn't want them on the ground. my bad! :) – hammythepig Mar 11 '14 at 16:26
  • 1
    How could I add special data an item say, refilling the chest with white dyed invulnerable leather armor? – DatEpicCoderGuyWhoPrograms May 23 '14 at 12:06
  • 1
    @DatEpicCoderGuyWhoPrograms Yes you can. Use /blockdata X Y Z {Items:[{id:leather_chestplate,Count:1,Slot,0,tag:{custom tags go here}]} Preferably start a new thread for that question. – RetroCraft Jun 19 '14 at 19:00
1

You could have two chests set up and connected with a hopper from one to the other. Use the blockdata tag on the top chest to add the item. It will be sucked into the second chest, and added to whatever items are already there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.