write down the seed for the world.
Place all your stuff from it in a chest
Back up the save.
Make a new world using the same seed from the world you wish to allow cheats on.
Make sure cheats are allowed on it.
Copy the dat files from the new save file to the old one.
You should now be able to delete the new save folder. Keep the original save folder and its backup though.
Download NBT Edit. Open it then navigate to your saves folder in your .minecraft folder. Open the save folder that you want cheats for then open the level.dat. Then double click on the Data tab then double click allow commands and when it says enter value chnge the 0 to a 1 and hit enter and save. Now run Minecraft and open the world and you should be able to use cheats.
Dude, there IS a way to do this! you need to download NBT Explorer made by Jaquardo! when you open the download, click the world you want to edit, then click the level.dat file. Once you do that, press data and enable cheats to 1, not 0! If this is hard to understand, I will do a video on it. My channel is Deathblood228
I had to do this yesterday after a 1.3.1 bug caused me to die and have no way of retrieving my things (the chunk hadn't loaded).
I did as others said and opened it to a lan with cheats enabled. I had to use my own username in it though. So /give myname 66 64 gave me 64 rails (I had a lot of rails on me to set up a system to move villagers closer to home).
If you save and quit the cheats are no longer enabled.
Ill post a picture tutorial of how to do this with NBT explorer in a couple hours when i get home
BEFORE WE START, PLEASE MAKE SURE YOU'VE CLOSE MINECRAFT (THE LAUNCHER DOES NOT NEED TO BE CLOSED, BUT THE GAME MUST BE CLOSED COMPLETELY, NOT JUST AT THE TITLE SCREEN IT MUST BE CLOSED).
Alright here's the picture tutorial:
As you can see by the picture, you first want to click the plus sign to expand the world you wish to enable cheats in (for me its Clocks). Then you need to expand the level.dat 'crate' inside what you've just opened up. Inside the level.dat, you'll find only one thing, a box called Data with a number of entities, expand that too. Inside hear, your first tag listed should be allowCommand (alphabetical order) and the value will be 0, as it is in my picture. Click on this tag (make sure it is highlighted in blue) and then click on the pencil on the toolbar above. After this, a popup box saying "Edit Value..." will appear. Change the value from 0 to 1 (DON'T PUT ANYTHING ELSE) and hit enter. After this, MAKE SURE TO HIT THE SAVE ICON ON THE TOOLBAR ABOVE OR NO CHANGES WILL BE MADE. Then exit NBTExplorer and open up minecraft. When you open the world you should have access to all commands, or cheats that are built in.
NOTE: minecraft does not fully save worlds until you exit the game completely. This is why you must close the game before this, and before using MCEdit. Furthermore, I had previously found a glitch in which you can have normal chunks in a flatworld due to this bug and naming issues. I made the post so you can find it on my page if you are interested. I hear people are turning that kinda map into a challenge map now.
Let me know if you still can't get this to work or you have other questions by messaging me or replying to this topic. Quote me if need be.
EDIT: Click the image to enlarge. Also feel free to right click and open image in new tab, because its a full screen image and so the resolution is on the high size (but I do have a pretty small screen so idk)