[Tutorial] How to create a simple laser beam in MCreator!

Started by Sajevius on

Topic category: User side tutorials

Last seen on 08:14, 28. Nov 2023
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[Tutorial] How to create a simple laser beam in MCreator!
Fri, 05/21/2021 - 07:03 (edited)

Hey there! Have you ever wanted to make a working, damaging laser beam in Minecraft? I mean why not, lasers are cool, and many people could find a use for it! I've also wanted to make one for the longest time. However, it was almost impossible to achieve such a thing with MCreator before. Many people might have either waited for it to be added in new updates, resorted to coming up with their own procedure, wrote custom code to make it possible, or just gave up and might've said "dang, MCreator is so limited! what a shame". But now, in case you wanted one but are entirely clueless as to how to achieve such a thing in MCreator, then look no further, for I'm here to show you a workaround I came up with for making lasers (and pretty much any type of beam) in MCreator! Yes, you read that right, lasers in MCreator, finally! There will be a few changes you have to make to the code so that it'll work properly against mobs though, but it shouldn't be hard, and I'll walk you through it!

(Before we start, here's a little video demostrating it: https://i.imgur.com/oT5zp27.mp4)


REQUIREMENTS:

  • MCreator 2020.5 and above
  • Forge 1.15.2/1.16.5
  • Procedure system knowledge
  • Basic Java & MC source code knowledge (specifically about damage sources; required for the laser to make shot mobs angry at you)

BACKGROUND INFO:

  • We will use moveable particles (e.g. dragon breath, flame, custom particles that don't have speed factor value set to 0) for the beam's visuals instead of creating our own renderer, so that means no code regarding the visuals will be involved!
  • We'll be making 2 types of laser that'll have different behaviors:
    • first one will damage mobs without angering them (procedures only, easier, ignores armor defense points, but doesn't make killed mobs drop XP)
    • second one will damage mobs and makes them hostile toward the shooter (involves changing a few parts of code, slightly harder, but works accordingly with armor defense points for balancing and makes killed mobs drop XP)
  • This laser is very basic, and when shooting it directly upwards or downwards, the particles won't move straight (the angle where the particles can move using this method is limited), but it will still damage mobs there

STEPS:

  1. Download the procedure template for the beam here to get started.
  2. Create an item/tool that will shoot the laser.
  3. Go to the item's triggers and add a procedure for "When item right-clicked in air".
  4. Once you're in the editor, import the laser procedure template you just downloaded.
  5. Save the procedure, remember the name you put for the procedure (for later use), and make sure it's attached to the proper trigger.
  6. Test it in-game to see if everything works. If it did, you can either stay with that procedure, or you can unlock the procedure code and modify it to actually anger shot mobs; It depends on exactly what you want

Now, when you want to have the beam actually make hit mobs get angry, here's what to do:

  • Lock the code of the laser procedure
  • Find this line in the procedure code:
Entity entity = (Entity) dependencies.get("entity");

            We have to change from type Entity to LivingEntity in order for this to work and not make the console give annoying warnings, so change that line into:

LivingEntity entity = (LivingEntity) dependencies.get("entity");

 https://i.imgur.com/gC5jjtD.pnghttps://i.imgur.com/zkrN3KL.png

  • Finally, find this line:
entityiterator.attackEntityFrom(DamageSource.MAGIC, (float) 5);

https://i.imgur.com/J4uvvlV.png

            And change it to:

entityiterator.attackEntityFrom(DamageSource.causeMobDamage(entity), (float) DAMAGE_AMOUNT);

            (please remember to replace "DAMAGE_AMOUNT" with any number you want for the damage!)

https://i.imgur.com/z1VKgOB.pnghttps://i.imgur.com/aBgRFOZ.pnghttps://i.imgur.com/o2U0tFq.png


And yeah, that's all it takes! Planning and organizing this was no easy task, and I hope you liked this tutorial & learned something from it! Enjoy experimenting with lasers/whatever beam attack you can make :D

Edited by Sajevius on Fri, 05/21/2021 - 07:03
Last seen on 04:15, 27. Mar 2024
Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Wow. The amount of effort…
Wed, 05/26/2021 - 03:43

Wow. The amount of effort that went into this is incredible.

Last seen on 10:47, 24. Oct 2022
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Nice!
Sat, 08/21/2021 - 18:36

Nice!

Last seen on 11:40, 4. Jun 2023
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can i make an entity that…
Tue, 08/31/2021 - 19:56

Can i make an entity that fires laser like this?

Last seen on 08:14, 28. Nov 2023
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
technically yeah, i think…
Tue, 08/31/2021 - 22:10

technically yeah, i think you should be able to make a laser-shooting entity with this, but since MCreator can't make custom AI goals yet you might wanna put that in an entity trigger of your mob... but personally trying it myself, it had visual bugs w/ particle spawning for some odd reason tho the damage itself works :/

Last seen on 10:36, 28. Jul 2022
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how would we do the last…
Thu, 11/25/2021 - 02:17

how would we do the last step in 1.17?

Last seen on 15:34, 28. Mar 2024
Joined Jun 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can you place blocks instead…
Sun, 02/20/2022 - 20:10

Can you place blocks instead of particles ?

Last seen on 17:00, 15. Aug 2023
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how to add more particles?  
Tue, 09/06/2022 - 13:30

how to add more particles?

 

Last seen on 11:21, 25. Apr 2023
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how to make beam like an its…
Wed, 09/28/2022 - 08:42

how to make beam like an its spawn particle, that doesnt move in direction you looking and if its collide with entity its deal damage (im bad at english)

 

Last seen on 19:35, 26. Mar 2024
Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
can you tell us how to…
Tue, 06/27/2023 - 07:06

can you tell us how to control its width so it will be like a sweep that will be pretty cool

Last seen on 00:18, 29. Mar 2024
Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
For me, for whatever reason,…
Fri, 08/04/2023 - 22:31

For me, for whatever reason, when there's anything in the final if do block (where [deal 5 damage to entity iterator type: MAGIC] is) it invalidates all instances of Entity Iterator and gives me 5 errors saying "Block entity_iterator is not supported by the selected generator!". Now I'd think that this is due to me being on Forge 1.19.4 MCreator 2023.2, but my friend who also launched on Forge 1.19.4 MCreator 2023.2 did not have this error. do you know of any reason why this could be?

Last seen on 19:56, 27. Mar 2024
Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How would you use this as a…
Sat, 08/05/2023 - 23:22

How would you use this as a mobs attack?

Last seen on 19:56, 27. Mar 2024
Joined Jun 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I managed to get a mob to…
Sat, 08/05/2023 - 23:30

I managed to get a mob to shoot the lazer but it doesn't show the particles?

Last seen on 23:57, 28. Feb 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
hey, i was wondering if it…
Fri, 08/25/2023 - 02:56

hey, i was wondering if it was possible to turn the laser beam to be a healing beam