DEV Community

nshmura
nshmura

Posted on

[mincraft][forge1.16] example code: Explode on block placed

Make explode on BlockEvent.EntityPlaceEvent

package com.nshmura.doromod;

import net.minecraft.entity.Entity;
import net.minecraft.world.Explosion;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod(ExampleMod.MOD_ID)
public class ExampleMod {
    public static final String MOD_ID = "examplemod";

    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger(MOD_ID);

    public ExampleMod() {
        MinecraftForge.EVENT_BUS.register(this);
    }

    @SubscribeEvent
    public void on(BlockEvent.EntityPlaceEvent event) {
        Entity entity = event.getEntity();
        entity.getCommandSenderWorld().explode(
                entity,
                entity.position().x,
                entity.position().y,
                entity.position().z,
                4.0F,
                Explosion.Mode.NONE
        );
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)