[TURORIAL (1.14)] How to Spawn Block Particles

Started by rmsandegs on Mon, 03/09/2020 - 04:37

Topic category: User side tutorials

Last seen on 23:51, 23. Oct 2020
Joined May 2014
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
[TURORIAL (1.14)] How to Spawn Block Particles
Tue, 03/17/2020 - 21:55 (edited)

I had to do a ton of research and fiddling to get this to work. So, to help others who need this (I assume there are quite a few), here is a full tutorial on how to spawn block particles from any block including modded ones!

I AM NOT A JAVA PRO. IF ANYTHING IS WRONG IN THIS TUTORIAL, PLEASE CORRECT ME.

First, you should know that this does require custom code. But before your eyes glaze over and you click away, please know that it's EXTREMELY simple to do (just 1 line of code!). I will give examples and create a basic skeleton if you want to copy-paste. Also know that you can put this in a regular procedure by dragging a "custom code snippet" block from the advanced tab and typing your code in there, and it will work most of the time (not always). So now that that's aside, let's get into it.

How to spawn block particles:

world.addParticle(new BlockParticleData(ParticleTypes.BLOCK, Blocks.[ID of block here in ALL CAPS].getDefaultState()), [x position], [y position], [z position], 0.0, 0.0, 0.0);

[ID of block in ALL CAPS] is where you put the ID of the block you want the particles to look like. If I wanted to make dirt particles I'd say: Blocks.DIRT, or Blocks.EMERALD_ORE for emerald ore.

If you want the particles to look like a block you've added to your mod, it will look slightly different:

world.addParticle(new BlockParticleData(ParticleTypes.BLOCK, MCreator[Name of mod element].block.getDefaultState()), [x position], [y position], [z position], 0.0, 0.0, 0.0);

[Name of mod element] refers to the name of the element when you see it in your "WORKSPACE" tab. There are no spaces. The name is prefaced by "MCreator" because that's how MCreator puts that in front of all your elements when it's writing its code for easier tracking or something. Either way, it is crucial that you leave that there. An example of this would be, if I had an element named LeadOre: MCreatorLeadOre.block. Fairly simple, I'd hope.

ADDENDUM: As of MCreator v2020.2, custom blocks are stored internally in a different way. In our example, instead of typing "MCreatorLeadOre.block", you'd type "LeadOreBlock.block".

Now we move on to the three position tags (x, y, and z). If you are in any way into modding, then I'd assume you know what these mean. They are the three planes of existence in Minecraft itself. In our case, they tell the game exactly where to spawn the particle.

There are two types of positions in Minecraft. There are block positions, or BlockPos, which are whole numbers and represent an absolute place in the world. But, there are also entity positions which are relative to entities in the world like mobs, animals, and players. Because of these two different types of positions, there are two different ways to tell the game where to spawn your particles:

If an entity is what's emitting the particles, then use this to tell your three positions:

(entity.posX, entity.posY, entity.posZ)

Pretty straightforward, right? If you want to shift the position in any direction, simply use an addition (+) or subtraction (-) symbol followed by the number of blocks to move in. Read this Minecraft Wiki Article for more information on coordinates.

Examples:

2 blocks west of the entity:                                   (entity.posX - 2, entity.posY, entity.posZ)

1 block north of the entity:                                    (entity.posX, entity.posY, entity.posZ - 1)

0.5 blocks east and 3 blocks up from the entity:   (entity.posX + 0.5, entity.posY + 3, entity.posZ)

 

If it's a block or anything else emitting the particles:

(new BlockPos(world.getPosition().getX(), world.getPosition().getY(), world.getPosition().getZ()))

Unfortunately, it's not so straightforward at first glance, but it functions in the same way as the entity version of x, y, and z do. They can be treated the same way.

The last thing I want to tell you is that you can randomize the position of particles, too! You can use the simple "phrase" Math.random() to generate a random number between 0 and 1. Then, just add it to your position.

Examples:

random amount between 0 and 1 blocks north of entity:      (entity.posX, entity.posY, entity.posZ - Math.random())

random amount between 0 and 1 blocks north of block:      (new BlockPos(world.getPosition().getX(), world.getPosition().getY(), world.getPosition().getZ() - Math.random()))

random amount between 0 and 5 west of entity:                  (entity.posX - Math.random() * 5, entity.posY, entity.posZ)

random amount between 0 and 5 blocks north of block:      (new BlockPos(world.getPosition().getX() - Math.random() * 5, world.getPosition().getY(), world.getPosition().getZ()))

 

It's also possible to mix-and-match numbers and randomness:

random amount between 2 blocks west and 2 blocks east of entity:    (entity.posX + 2 - Math.random() * 4, entity.posY, entity.posZ)

random amount between 2 blocks west and 2 blocks east of block:    (new BlockPos(world.getPosition().getX() + 2 - Math.random() * 4, world.getPosition().getY(), world.getPosition().getZ()))

 

 I hope you found this helpful and I hope I didn't make any mistakes. Feel free to leave questions in the comments if you're unsure about something!

Edited by rmsandegs on Tue, 03/17/2020 - 21:55
Last seen on 04:38, 20. Oct 2020
Joined Jun 2019
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
:O amazing tutorial
Mon, 03/09/2020 - 04:43

:O

amazing tutorial