mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Added Explosion Start and Detonate events to control explosion.
This commit is contained in:
1 parent
1fc1570663
commit
42938a1e7f
5 files changed
+157
-31
No files matched your search
@@ -3,7 +3,9 @@ package net.minecraftforge.event;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -21,6 +23,8 @@ import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
@@ -57,6 +61,7 @@ import net.minecraftforge.event.entity.player.UseHoeEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent.MultiPlaceEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent.PlaceEvent;
|
||||
import net.minecraftforge.event.world.ExplosionEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
@@ -346,4 +351,25 @@ public class ForgeEventFactory
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerEvent.Clone(player, oldPlayer, wasDeath));
|
||||
}
|
||||
|
||||
public static boolean onExplosionStart(World world, Explosion explosion)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new ExplosionEvent.Start(world, explosion));
|
||||
}
|
||||
|
||||
public static void onExplosionDetonate(World world, Explosion explosion, List<Entity> list, double diameter)
|
||||
{
|
||||
//Filter entities to only those who are effected, to prevent modders from seeing more then will be hurt.
|
||||
/* Enable this if we get issues with modders looping to much.
|
||||
Iterator<Entity> itr = list.iterator();
|
||||
Vec3 p = explosion.getPosition();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
Entity e = itr.next();
|
||||
double dist = e.getDistance(p.xCoord, p.yCoord, p.zCoord) / diameter;
|
||||
if (e.func_180427_aV() || dist > 1.0F) itr.remove();
|
||||
}
|
||||
*/
|
||||
MinecraftForge.EVENT_BUS.post(new ExplosionEvent.Detonate(world, explosion, list));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package net.minecraftforge.event.world;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/** ExplosionEvent triggers when an explosion happens in the world.<br>
|
||||
* <br>
|
||||
* ExplosionEvent.Start is fired before the explosion actually occurs.<br>
|
||||
* ExplosionEvent.Detonate is fired once the explosion has a list of affected blocks and entities.<br>
|
||||
* <br>
|
||||
* ExplosionEvent.Start is {@link Cancelable}.<br>
|
||||
* ExplosionEvent.Detonate can modify the affected blocks and entities.<br>
|
||||
* Children do not use {@link HasResult}.<br>
|
||||
* Children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
*/
|
||||
public class ExplosionEvent extends Event
|
||||
{
|
||||
public final World world;
|
||||
public final Explosion explosion;
|
||||
|
||||
public ExplosionEvent(World world, Explosion explosion)
|
||||
{
|
||||
this.world = world;
|
||||
this.explosion = explosion;
|
||||
}
|
||||
|
||||
/** ExplosionEvent.Start is fired before the explosion actually occurs. Canceling this event will stop the explosion.<br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable}.<br>
|
||||
* This event does not use {@link HasResult}.<br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Start extends ExplosionEvent
|
||||
{
|
||||
public Start(World world, Explosion explosion)
|
||||
{
|
||||
super(world, explosion);
|
||||
}
|
||||
}
|
||||
|
||||
/** ExplosionEvent.Detonate is fired once the explosion has a list of affected blocks and entities. These lists can be modified to change the outcome.<br>
|
||||
* <br>
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
* This event does not use {@link HasResult}.<br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
*/
|
||||
public static class Detonate extends ExplosionEvent
|
||||
{
|
||||
private final List<Entity> entityList;
|
||||
|
||||
public Detonate(World world, Explosion explosion, List<Entity> entityList)
|
||||
{
|
||||
super(world, explosion);
|
||||
this.entityList = entityList;
|
||||
}
|
||||
|
||||
/** return the list of blocks affected by the explosion. */
|
||||
public List<BlockPos> getAffectedBlocks()
|
||||
{
|
||||
return explosion.func_180343_e();
|
||||
}
|
||||
|
||||
/** return the list of entities affected by the explosion. */
|
||||
public List<Entity> getAffectedEntities()
|
||||
{
|
||||
return entityList;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user