Browse Source

extension of explosion event

Kajetan Johannes Hammerle 4 years ago
parent
commit
589027a950

+ 0 - 9
src/main/java/me/km/CommonEvents.java

@@ -2,20 +2,11 @@ package me.km;
 
 import me.km.blocks.ModBlocks;
 import me.km.items.ModItems;
-import me.km.utils.ExplosionUtils;
 import net.minecraft.item.Item;
 import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent;
-import net.minecraftforge.event.world.ExplosionEvent;
 import net.minecraftforge.eventbus.api.SubscribeEvent;
 
 public class CommonEvents {
-    @SubscribeEvent
-    public void onExplosionDetonation(ExplosionEvent.Detonate e) {
-        if(!e.isCanceled()) {
-            ExplosionUtils.explosion(e.getExplosion(), e.getWorld());
-        }
-    }
-
     @SubscribeEvent
     public void getFuelBurnTime(FurnaceFuelBurnTimeEvent e) {
         Item item = e.getItemStack().getItem();

+ 14 - 1
src/main/java/me/km/snuviscript/ScriptEvents.java

@@ -13,6 +13,7 @@ import me.km.entities.EntityItemProjectile;
 import me.km.events.CommandEvent;
 import me.km.inventory.ModInventory;
 import me.km.permissions.Permissions;
+import me.km.utils.ExplosionUtils;
 import me.km.utils.Location;
 import net.minecraft.command.ICommandSource;
 import net.minecraft.entity.Entity;
@@ -601,9 +602,21 @@ public class ScriptEvents {
     }
 
     @SubscribeEvent(receiveCanceled = true, priority = EventPriority.HIGHEST)
-    public void onExplosion(ExplosionEvent.Start e) {
+    public void onPreExplosion(ExplosionEvent.Start e) {
         e.setCanceled(true);
+        handleEvent(e, "pre_explosion", sc -> {
+            sc.setVar("damage_source", e.getExplosion().getDamageSource());
+            sc.setVar("location", new Location(e.getWorld(), e.getExplosion().getPosition()));
+        }, null);
+    }
+    
+    @SubscribeEvent
+    public void onExplosion(ExplosionEvent.Detonate e) {
+        ExplosionUtils.explosion(e.getExplosion(), e.getWorld());
         handleEvent(e, "explosion", sc -> {
+            sc.setVar("affected_blocks", e.getAffectedBlocks());
+            sc.setVar("affected_entities", e.getAffectedEntities());
+            sc.setVar("damage_source", e.getExplosion().getDamageSource());
             sc.setVar("location", new Location(e.getWorld(), e.getExplosion().getPosition()));
         }, null);
     }

+ 6 - 0
src/main/java/me/km/snuviscript/commands/LocationCommands.java

@@ -3,6 +3,7 @@ package me.km.snuviscript.commands;
 import me.hammerle.snuviscript.code.ScriptManager;
 import me.km.utils.Location;
 import me.km.world.WorldManager;
+import net.minecraft.util.math.BlockPos;
 import net.minecraft.util.math.MathHelper;
 import net.minecraft.world.World;
 
@@ -17,6 +18,11 @@ public class LocationCommands {
             }
             return new Location((World) in[0].get(sc), in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc), 0, 0);
         });
+        sm.registerConsumer("loc.setblockpos", (sc, in) -> {
+            Location l = (Location) in[0].get(sc);
+            BlockPos pos = (BlockPos) in[1].get(sc);
+            l.set(pos.getX(), pos.getY(), pos.getZ());
+        });
         sm.registerFunction("loc.getx", (sc, in) -> ((Location) in[0].get(sc)).getX());
         sm.registerFunction("loc.gety", (sc, in) -> ((Location) in[0].get(sc)).getY());
         sm.registerFunction("loc.getz", (sc, in) -> ((Location) in[0].get(sc)).getZ());