Topic category: User side tutorials
This tutorial will explain how to edit the water level of a cauldron, for example to clean items or to make machines that use cauldrons. It does require some custom code, but you can just copy-paste the one from this tutorial. At the end of the tutorial, you can find some template procedures which you can download.
How do cauldrons work?
Blockstates are extra info stored by some blocks, such as the block's rotation, whether it's being powered by redstone or whether it's active. Cauldrons use blockstates to store their water level: it's an integer number between 0 (empty) and 3 (full). However, MCreator doesn't have blockstate procedures (yet), so it's impossible to get the water level of a cauldron without some custom coding. Thanks to the "Custom code snippet" block, it's possible to create a procedure that interacts with the water level of cauldrons.
Procedure (1.12)
The procedure requires the X Y Z and World dependencies. Also, don't add any local variable called "waterLevel". This example procedure will be triggered only if there's water inside the cauldron. It'll do some stuff, then it'll decrease the water level of the cauldron by one.
- Start by adding a "if Block at X Y Z = Cauldron", like in the image. All the next blocks will go inside this if statement.
- This is where custom code comes in. Copy this piece of code:
BlockPos pos = new BlockPos(x, y, z); IBlockState blockState = world.getBlockState(pos); int waterLevel = blockState.getValue(BlockCauldron.LEVEL); if (waterLevel > 0) {
on "custom code snippet" blocks (found in Advanced). You should use a block for each line, to make the code more readable. What this code does is:
-
stores the X Y Z as a BlockPos variable (to make the code cleaner)
-
stores the cauldron and its blockstate as an IBlockState variable
-
stores the water level of the cauldron as an integer variable (which is why you can't use "waterLevel" as a procedure local variable)
-
checks if the water level is greater than 0 (that is, if there's water in the cauldron)
-
-
Now you can add your procedure blocks: apply an effect to the entity, spawn particles, remove items from your inventory etc. Do not remove the cauldron, as it'll be placed back anyway in the next step;
-
Add more custom code snippets with these lines:
world.setBlockState(pos, blockState.withProperty(BlockCauldron.LEVEL, waterLevel - 1)); }
The first line decreases the water level of the cauldron by 1, the second one closes the "if (waterLevel > 0) {" statement.
This should be the final result:
-
Save the procedure and recompile. If you did everything correctly, you shouldn't get recompilation errors
Customization
- The cauldron isn't at x y z, but somewhere else: copy all the changes you do to the "Get block at X Y Z" block on the 1st code snippet. Example:
In this example, the cauldron is at X, Y+1 and Z-2. All the changes I applied to the "Get block" are copied in the first custom code block.
- Execute if the cauldron isn't full, and increase water level by one:
- In the 4th code snippet, write
if (waterLevel < 3) {
- In the 5th code snippet, write
waterLevel + 1
instead ofwaterLevel - 1
- In the 4th code snippet, write
- Execute if the cauldron is empty, and fill it completely:
- In the 4th code snippet, write
if (waterLevel == 0) {
- In the 5th code snippet, write
3
instead ofwaterLevel - 1
- In the 4th code snippet, write
- Execute if the cauldron is full, and remove all the water:
- In the 4th code snippet, write
if (waterLevel == 3) {
- In the 5th code snippet, write
0
instead ofwaterLevel - 1
- In the 4th code snippet, write
- Do not change the water level of the cauldron: remove the 5th code snippet. You can also replace the cauldron with another block if you wish so (for example by adding a "Place block at X Y Z" procedure)
- You can change the values of the previous examples if you want to, but keep in mind that waterLevel should always be between 0 and 3. If you write something like
if (waterLevel == 4) {
, the procedure won't be executed
1.14
The code in Minecraft 1.14.4 is different than the one in 1.12.2. If you do the same steps as above in 1.14, you'll get recompilation errors. To make it work in 1.14, you'll need to use these code lines instead:
BlockPos pos = new BlockPos(x, y, z);
BlockState blockState = world.getBlockState(pos);
int waterLevel = blockState.get(CauldronBlock.LEVEL);
if (waterLevel > 0) {
// Your procedure blocks
world.setBlockState(pos, blockState.with(CauldronBlock.LEVEL, waterLevel - 1));
}
Template download links:
These are the procedures used in the examples (for 1.12):
WOW! I could use cauldrons for my mod bedrock alchemy now! Thank you so much
Very nice tutorial, good job! :)
@SomeoneElse, you should apply as wiki contributor
I agree with crispy chips :)
Lo and behold! :P
Anyway, tidied up the tutorial and added some templates you can download!
This doesn't work for 1.14, can you help me?
Code in 1.14 is different, that's why it won't work. I added the code you need to use for 1.14; I'll add the templates later
What should I write if I want to do this with crops?
It didn't work for me on 1.15.2, can anyone please help me?
Am trying to make an ingot that gets transformed into an unheated one when used in a cauldron. Please anyone help me.
Thank you so much, this worked perfectly for me.
Can anyone help me out with this on 1.16.5?
How to do it on 1.16.5?