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
Neat! :D
Wow. The amount of effort that went into this is incredible.
Nice!
Can i make an entity that fires laser like this?
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 :/
how would we do the last step in 1.17?
Can you place blocks instead of particles ?
how to add more particles?
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)
can you tell us how to control its width so it will be like a sweep that will be pretty cool
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?
How would you use this as a mobs attack?
I managed to get a mob to shoot the lazer but it doesn't show the particles?
hey, i was wondering if it was possible to turn the laser beam to be a healing beam