[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 13:35, 23. Apr 2024
Joined Oct 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how to make the same but…
Tue, 12/26/2023 - 15:47

how to make the same but with a laser block instead of a laser gun

 

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

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make this a keybind? 
Mon, 01/29/2024 - 01:45

How to make this a keybind? 

Last seen on 16:57, 14. Apr 2024
Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hey, this post is still…
Fri, 03/15/2024 - 15:27

Hey, this post is still helpful in 2024 :D
Question, is there a way to make particles be seen to all players??