Changing the block state of an existing block

I'm trying to create a function that will generate a door, with random material, orientation and hinge placement. I have tackled the RNG part already, but cannot find a way to incrementally build the door so that I don't have to manually write down all of the possible combinations (aka 96 carefully-written commands).

I'm currently trying to achieve the following sequence:

  • Roll the RNG to select the material for the next command
  • fill ~ ~ ~ ~ ~1 ~ minecraft:<?>_door replace
  • <set half = upper at ~ ~1 ~>
  • Roll for orientation
  • <set facing = <?> at ~ ~ ~>, <set facing = <?> at ~ ~1 ~>
  • Roll for hinge placement
  • <set hinge = <?> at ~ ~ ~>, <set hinge = <?> at ~ ~1 ~>

What I'm missing is the imaginary <set state at> command. I've gathered that setblock has some ability to update existing blocks but this seems to be both unreliable and restricted to tile entities, and requires to know what block exactly I'm replacing. data is also explicitly restricted to tile entities.

How can I change the block state of an existing, unknown block?


Sadly this is not possible. You need to write at least one command per possible state. Luckily, SethBling recently did something very similar, so you can use his commands and modify them to your needs: https://sethbling.s3-us-west-2.amazonaws.com/Downloads/DataPacks/minecraft_earth.zip

I recommend for example Notepad++, which can use search+replace for all files in a folder at once.