How to import stuff when using code snippets?

Started by andy321 on

Topic category: Help with MCreator software

Joined Aug 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to import stuff when using code snippets?

How do I add dependencies as import statements when using custom code snippets?
I read in another post here which said that it should be automatically handled but it isn't for me.


For example if I want to use the snippet:
entity.startSleeping(BlockPos.containing(entity.getX(), entity.getY(), entity.getZ()));

to force an entity to sleep it would require some stuff like:
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Pose;

but none of it will be added and if I do it with another code snippet, it would be placed somewhere in the middle of the procedure's function resulting in errors.

The only workaround I have found for some cases so far is placing if statements with some built in functions that import the required dependencies in the code with some no-op substitute so they won't affect my code. But that's a very weird way to solve it and does not work in every case. Has somebody found a better solution?