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

Started by Sajevius on Fri, 05/21/2021 - 03:32

Topic category: User side tutorials

Last seen on 09:28, 30. Nov 2021
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 08:25, 30. Nov 2021
Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 12:05, 24. Nov 2021
Joined Aug 2020
Points:

User statistics:

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

Nice!

Last seen on 14:29, 10. Oct 2021
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 09:28, 30. Nov 2021
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 20:28, 27. Nov 2021
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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?