Started by
AnnoxQrystal
on
Topic category: Help with Minecraft modding (Java Edition)
I am currently creating a mod and have added a block that has gravity. I want this block to have the property that when it falls to the ground, it destroys itself (whether it falls on an not full block, such as a chest or torch, which cause such a block to destroy itself when it falls, or not at all when it falls on a regular block) but does not drop. Does anyone know how to do this?
Maybe "if not air at Y -1 do break block" on tick update? I have not made blocks with gravity before but try it and see if it works.
(My English is bad, I'm Chinese)
Try to create a Function and add it to the "TickFunction" tag, and write this in it:
Please turn "you_mod_id:you_block_id" into yours.
Create a procedure, you just should let it place an air at where it is, assuming you name it "Broken".
Now you should modify you code of the block(so please make sure you don’t need to modify the basic properties of this block.)
and you should turn this code into you old code:
Please place the following code on the first line inside the first pair of {} after the first occurrence of the word "public" that you see.
public static final BooleanProperty BROKEN = BooleanProperty.create("broken");
And now you can see many "import", please place the following code in their respective lines, regardless of the line number.
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.BlockState;
import net.mcreator. .procedures.BrokenProcedure;
Fill in your mod id in the blank, without "_", and make sure to replace ‘Broken’ with the name you previously assigned.
Add the following code after the second-to-last "{" in the entire code block, and make sure to replace "Broken" with the name you previously assigned.
@Override
public void tick(BlockState blockstate, ServerLevel world, BlockPos pos, RandomSource random) {
super.tick(blockstate, world, pos, random);
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
if (blockstate.getValue(BROKEN)) {
BrokenProcedure.execute(world, x, y, z);
}
world.scheduleTick(pos, this, 1);
}
Now you block will broke when it land.