Make a certain block unplaceable?

I was wondering if there is a way to make a block such as bedrock or obsidian unplaceable in a certain area, because I wanted to give players creative mode for a game, but I don't want them to use bedrock or obsidian in their creations. Is there any way to make a block unplaceable using commands?


Solution 1:

You could testfor anyone with obsidian or bedrock in there inventory and if they have it then remove it. /testfor @a[r=10] {Inventory:[{id:"minecraft:obsidian"}]}

/clear @a[r=10] minecraft:obsidian

Or another method is, you could testfor the player holding the obsidian and bedrock in there hand with a command like this:

/testfor @a[r=10] {Inventory:[{Slot:0b,id:"minecraft:obsidian"}]} If you wanted to use this method you would have to testfor slots 0-8, just change the zero.

then if you didn't want to remove the item you could change there gamemode to adventure

/gamemode a @a[r=10]

increasing the radius will increase the area you wish them not to place those blocks.

For the second method I suggest having a clock hooked up to the testfor command that triggers a sticky piston with a redstone block on the end. When the testfor activates true then the sticky piston will extend activating the gamemode change. When they leave the radius the sticky piston will deactivate pulling the redstone block into another gamemode command returning them to there previous gamemode. It would look somthing like this:enter image description here I think method one would be more useful in your case.

Solution 2:

I just realized that the easiest way to do this is to have a fill clock setting off two command blocks that replace all bedrock/obsidian with air.