mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 11:59:25 +00:00
Added Explosion Start and Detonate events to control explosion. Closes #1469
This commit is contained in:
1 parent
6910f40fc2
commit
861c00fdfc
5 files changed
+157
-33
No files matched your search
@@ -2,7 +2,9 @@ package net.minecraftforge.event;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import cpw.mods.fml.common.eventhandler.Event.Result;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -16,6 +18,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
@@ -38,6 +41,7 @@ import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
|
||||
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;
|
||||
|
||||
public class ForgeEventFactory
|
||||
@@ -216,4 +220,24 @@ public class ForgeEventFactory
|
||||
File dir = ObfuscationReflectionHelper.getPrivateValue(SaveHandler.class, sh, "playersDirectory", "field_"+"75771_c");
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerEvent.LoadFromFile(player, dir, uuidString));
|
||||
}
|
||||
|
||||
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();
|
||||
while (itr.hasNext())
|
||||
{
|
||||
Entity e = itr.next();
|
||||
double dist = e.getDistance(explosion.explosionX, explosion.explosionY, explosion.explosionZ) / diameter;
|
||||
if (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 cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
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<ChunkPosition> getAffectedBlocks()
|
||||
{
|
||||
return explosion.affectedBlockPositions;
|
||||
}
|
||||
|
||||
/** return the list of entities affected by the explosion. */
|
||||
public List<Entity> getAffectedEntities()
|
||||
{
|
||||
return entityList;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user