how to make a weapon that by right clicking generates an explosion that does not destroy blocks

Started by davidS on Thu, 06/25/2020 - 18:53

Topic category: Help with modding (Java Edition)

Last seen on 00:32, 27. Apr 2021
Joined Mar 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
how to make a weapon that by right clicking generates an explosion that does not destroy blocks
Thu, 06/25/2020 - 18:53

hello I want it to load like a bow and when I release it it explodes and does not harm the player

version 2020.3

google translate

Last seen on 17:22, 8. Jun 2021
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
you're asking two very…
Thu, 06/25/2020 - 20:25

you're asking two very different things in your title and post. what do you really want, for the explosion to not destroy blocks or not hurt the player?

Last seen on 00:32, 27. Apr 2021
Joined Mar 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
both
Thu, 06/25/2020 - 23:26

both

Last seen on 17:22, 8. Jun 2021
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
to make explosion not…
Fri, 06/26/2020 - 10:19

to make explosion not destroy blocks, instead of using the "Explode at {x} {y} {z} with power {n}", use a Custom code snippet and in the text field enter: "if (!world.isRemote) {world.createExplosion(null, entity.posX, entity.posY, entity.posZ, (float) 5, false);}" and replace the 5 with the explosion power you desire. make sure that "world" is showing up in the Required Dependencies on the right side of the procedure page.

to make the explosion not hurt yourself, temporarily make yourself immune to damage. use Player procedure "Disable damage of [target entity] if [true] otherwise enable it" before the explosion and change the true to false after the explosion.

Last seen on 00:32, 27. Apr 2021
Joined Mar 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Where do I put the code you…
Fri, 06/26/2020 - 15:33

Where do I put the code you told me sorry for the inconvenience I do not know how to program

package net.mcreator.varius.procedures;

import net.minecraft.world.World;
import net.minecraft.world.Explosion;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.Entity;

import net.mcreator.varius.VariusModElements;

@VariusModElements.ModElement.Tag
public class MartillodediamanteRightClickedOnBlockProcedure extends VariusModElements.ModElement {
    public MartillodediamanteRightClickedOnBlockProcedure(VariusModElements instance) {
        super(instance, 33);
    }

    public static void executeProcedure(java.util.HashMap<String, Object> dependencies) {
        if (dependencies.get("entity") == null) {
            System.err.println("Failed to load dependency entity for procedure MartillodediamanteRightClickedOnBlock!");
            return;
        }
        if (dependencies.get("x") == null) {
            System.err.println("Failed to load dependency x for procedure MartillodediamanteRightClickedOnBlock!");
            return;
        }
        if (dependencies.get("y") == null) {
            System.err.println("Failed to load dependency y for procedure MartillodediamanteRightClickedOnBlock!");
            return;
        }
        if (dependencies.get("z") == null) {
            System.err.println("Failed to load dependency z for procedure MartillodediamanteRightClickedOnBlock!");
            return;
        }
        if (dependencies.get("world") == null) {
            System.err.println("Failed to load dependency world for procedure MartillodediamanteRightClickedOnBlock!");
            return;
        }
        Entity entity = (Entity) dependencies.get("entity");
        int x = (int) dependencies.get("x");
        int y = (int) dependencies.get("y");
        int z = (int) dependencies.get("z");
        World world = (World) dependencies.get("world");
        if (entity instanceof PlayerEntity) {
            ((PlayerEntity) entity).abilities.disableDamage = (true);
            ((PlayerEntity) entity).sendPlayerAbilities();
        }
        if (!world.isRemote) {
            world.createExplosion(null, (int) x, (int) y, (int) z, (float) 4, Explosion.Mode.BREAK);
        }
        if (entity instanceof PlayerEntity) {
            ((PlayerEntity) entity).abilities.disableDamage = (true);
            ((PlayerEntity) entity).sendPlayerAbilities();
        }
        if (entity instanceof PlayerEntity) {
            ((PlayerEntity) entity).abilities.disableDamage = (false);
            ((PlayerEntity) entity).sendPlayerAbilities();
        }
    }
}
 

Last seen on 17:22, 8. Jun 2021
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
enter this in the Custom…
Fri, 06/26/2020 - 16:33

https://cdn.discordapp.com/attachments/599250311852458006/726111960562794577/Untitled.png

enter this in the Custom code snippet text field:

if (!world.isRemote) { world.createExplosion(null, (int) x, (int) y, (int) z, (float) 4, Explosion.Mode.NONE); }