Topic category: User side tutorials
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:
- Download the procedure template for the beam here to get started.
- Create an item/tool that will shoot the laser.
- Go to the item's triggers and add a procedure for "When item right-clicked in air".
- Once you're in the editor, import the laser procedure template you just downloaded.
- Save the procedure, remember the name you put for the procedure (for later use), and make sure it's attached to the proper trigger.
- 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");
- Finally, find this line:
entityiterator.attackEntityFrom(DamageSource.MAGIC, (float) 5);
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!)
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
how to make the same but with a laser block instead of a laser gun
How to make this a keybind?
Hey, this post is still helpful in 2024 :D
Question, is there a way to make particles be seen to all players??
I'm inside the code editor, none of the lines you said are there? any help would be appreciated
Is it possible to make the lazer particles spin in a circle around the main lazer? like a lazer circling around another lazer