I am making an RPG map, and was wondering how to "save" the game. If you die, you would revert back to a save that happens automatically or manually, and I was wondering how to have it so that you will have all the items you had then, and none of the items you got after you saved (so /gamerule keepInventory won't work). The only way I can think of doing this is having this long, long, annoying set of command blocks to test for all the items in the game, and then have another 64 command blocks for each of those items, testing for the amount of the item.
Minecraft Java Edition – How to Save Minecraft Inventory Using Commands in Minecraft Java Edition
minecraft-commandsminecraft-java-edition
Related Solutions
Yes, I know it's a bit outdated but have you tried editing the level.dat
?
Just download this program and run it. Open the menu File > Open
and then select the level.dat
in C:/Users/[me]/AppData/Roaming/.minecraft/[matching mc world]/level.dat
. Then unfold to the followings Data > GameRules > doDaylightCycle
. Double-click to edit it and enter false
. Save and start the game.
This question is very difficult. Testing if two blocks are somehow connected is already difficult, two entities being in the same body of water is even harder. I have a solution, but it's not a great one. There are probably solutions that work a lot better.
I'd recommend instead looking back the actual problem that you want this solution for; see if there's another way to solve it without testing if two entities are in the same body of water.
This part is to make sure that a search will actually work and won't break your world.
First, we can easily make sure the entities are actually both in water. If either of them is not, then we can skip everything else as they can't both be in the same body of water if one of them isn't even in any water. Put an AND gate with these two commands:
/execute @e[name=Entity1] ~ ~ ~ /testforblock ~ ~ ~ water
/execute @e[name=Entity2] ~ ~ ~ /testforblock ~ ~ ~ water
Next I'd next check that the entities are at least somewhat near eachother. This is kind of a safeguard; they could still be in the same body of water thousands of blocks away, but it's unlikely and you'd crash the game trying to work it out anyway.
/execute @e[name=Entity1] ~ ~ ~ /testfor @e[name=Entity2,r=R] ~ ~ ~
Change R
out with however far you want the search to go for. This solution is laggy, so you may want to keep it small.
If that succeeds (the entities are both in water, and aren't ridiculously far away from each-other) then it's time to do the actual search that'll work out if they're in the same body of water.
This part is the actual search.
The following commands make both Entity1
and Entity2
summon marker
ArmorStands in every adjacent direction around them in which there is water. The -1 data type means that any type of water (flowing, source, etc.) will work:
/execute @e[name=Entity1] ~ ~ ~ detect ~1 ~ ~ water -1 /summon ArmorStand ~1 ~ ~ {CustomName:"Entity1",Marker:1b,NoGravity:1b}
/execute @e[name=Entity1] ~ ~ ~ detect ~-1 ~ ~ water -1 /summon ArmorStand ~-1 ~ ~ {CustomName:"Entity1",Marker:1b,NoGravity:1b}
/execute @e[name=Entity1] ~ ~ ~ detect ~ ~1 ~ water -1 /summon ArmorStand ~ ~1 ~ {CustomName:"Entity1",Marker:1b,NoGravity:1b}
/execute @e[name=Entity1] ~ ~ ~ detect ~ ~-1 ~ water -1 /summon ArmorStand ~ ~-1 ~ {CustomName:"Entity1",Marker:1b,NoGravity:1b}
/execute @e[name=Entity1] ~ ~ ~ detect ~ ~ ~1 water -1 /summon ArmorStand ~ ~ ~1 {CustomName:"Entity1",Marker:1b,NoGravity:1b}
/execute @e[name=Entity1] ~ ~ ~ detect ~ ~ ~-1 water -1 /summon ArmorStand ~ ~ ~-1 {CustomName:"Entity1",Marker:1b,NoGravity:1b}
/execute @e[name=Entity2] ~ ~ ~ detect ~1 ~ ~ water -1 /summon ArmorStand ~1 ~ ~ {CustomName:"Entity2",Marker:1b,NoGravity:1b}
/execute @e[name=Entity2] ~ ~ ~ detect ~-1 ~ ~ water -1 /summon ArmorStand ~-1 ~ ~ {CustomName:"Entity2",Marker:1b,NoGravity:1b}
/execute @e[name=Entity2] ~ ~ ~ detect ~ ~1 ~ water -1 /summon ArmorStand ~ ~1 ~ {CustomName:"Entity2",Marker:1b,NoGravity:1b}
/execute @e[name=Entity2] ~ ~ ~ detect ~ ~-1 ~ water -1 /summon ArmorStand ~ ~-1 ~ {CustomName:"Entity2",Marker:1b,NoGravity:1b}
/execute @e[name=Entity2] ~ ~ ~ detect ~ ~ ~1 water -1 /summon ArmorStand ~ ~ ~1 {CustomName:"Entity2",Marker:1b,NoGravity:1b}
/execute @e[name=Entity2] ~ ~ ~ detect ~ ~ ~-1 water -1 /summon ArmorStand ~ ~ ~-1 {CustomName:"Entity2",Marker:1b,NoGravity:1b}
Note that all of the new ArmorStands being summoned have the name of their summoner. This means that in the next iteration of the search, each of these ArmorStands will also summon more ArmorStands around them in directions that there is water, and so on. The entity that they come from will also be remembered by their name.
Follow all of that up with:
/execute @e[name=Entity1] ~ ~ ~ /setblock ~ ~ ~ red_sandstone
/execute @e[name=Entity2] ~ ~ ~ /setblock ~ ~ ~ red_sandstone
Any solid block will do fine. This is to mark the water blocks as already having a marker ArmorStand on them, so that the future water detects will not spawn another one on that tile.
Repeat all of this search on a clock that terminates when the search succeeds, or the search has gone on for a certain number (I'd recommend R) of iterations (or it'll keep on going forever if they aren't in the same body of water). This search should look like this for each entity:
To test if the search has succeeded, all you need to do is:
/execute @e[name=Entity1] ~ ~ ~ /testfor @e[r=1,Entity2]
Which will make each Entity1 ArmorStand look for adjacent Entity2 ArmorStands, at which point the two entities have been connected by an adjacent route.
To cleanup the all the red_sandstone and marker ArmorStands you just created for this search, all you need to do is:
/execute @e[name=Entity1] ~ ~ ~ /setblock ~ ~ ~ water
/execute @e[name=Entity2] ~ ~ ~ /setbock ~ ~ ~ water
/kill @e[name=Entity1, type=ArmorStand]
/kill @e[name=Entity2, type=ArmorStand]
And that's it done. This is very messy, but works well from what I've tried. It can detect if entities are connected even through mazes of water.
Related Topic
- Minecraft – Location specific inventory retention in Minecraft
- Minecraft Vanilla elevator
- Minecraft /xp wont let me target @p or @a
- Minecraft – Having trouble testing for mobs with command blocks
- Minecraft – How to test for a named item in a players inventory? (Minecraft 1.13)
- Minecraft – How to detect certain block types anywhere in a certain area
Best Answer
In Minecraft 1.14 and later versions, it is possible to copy the player's inventory to a chest without killing the player.
Note that this only copies the hotbar and the bottom two rows of the player's inventory, since players can carry slightly more stuff than can fit in a chest. If you want to copy the player's entire inventory to a double chest, you need a much more complicated trick.