mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-25 06:24:24 +00:00
Add TeleportEntityEvent that fires when any travel teleport happens
This commit is contained in:
1 parent
35835e2fe4
commit
e03d770d5d
3 files changed
+72
-10
No files matched your search
@@ -0,0 +1,50 @@
|
||||
package crazypants.enderio.api.teleport;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
|
||||
/**
|
||||
* An event that can be used to respond to, edit, and prevent entity teleports.
|
||||
* <p>
|
||||
* This event will fire under all circumstances:
|
||||
* <ul>
|
||||
* <li>Travel Anchors</li>
|
||||
* <li>Staff of travelling</li>
|
||||
* <li>Telepad</li>
|
||||
* </ul>
|
||||
*
|
||||
* As well as any externally added teleports, assuming they fire this event
|
||||
* manually.
|
||||
*
|
||||
*/
|
||||
@Cancelable
|
||||
public class TeleportEntityEvent extends EntityEvent {
|
||||
|
||||
/**
|
||||
* The target coords. These can be edited by event handlers.
|
||||
*/
|
||||
public int targetX, targetY, targetZ;
|
||||
|
||||
public final TravelSource source;
|
||||
|
||||
/**
|
||||
* Fired before an entity teleports to the given location.
|
||||
*
|
||||
* @param entity
|
||||
* The entity teleporting
|
||||
* @param x
|
||||
* The target X coord
|
||||
* @param y
|
||||
* The target Y coord
|
||||
* @param z
|
||||
* The target Z coord
|
||||
*/
|
||||
public TeleportEntityEvent(Entity entity, TravelSource source, int x, int y, int z) {
|
||||
super(entity);
|
||||
this.targetX = x;
|
||||
this.targetY = y;
|
||||
this.targetZ = z;
|
||||
this.source = source;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@@ -31,6 +32,7 @@ import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.api.teleport.IItemOfTravel;
|
||||
import crazypants.enderio.api.teleport.ITravelAccessable;
|
||||
import crazypants.enderio.api.teleport.TeleportEntityEvent;
|
||||
import crazypants.enderio.api.teleport.TravelSource;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.enderface.TileEnderIO;
|
||||
@@ -392,14 +394,14 @@ public class TravelController {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
sendTravelEvent(coord, source, requiredPower, conserveMomentum);
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
player.worldObj.spawnParticle("portal", player.posX + (rand.nextDouble() - 0.5D), player.posY + rand.nextDouble() * player.height - 0.25D,
|
||||
player.posZ + (rand.nextDouble() - 0.5D), (rand.nextDouble() - 0.5D) * 2.0D, -rand.nextDouble(),
|
||||
(rand.nextDouble() - 0.5D) * 2.0D);
|
||||
if(sendTravelEvent(player, coord, source, requiredPower, conserveMomentum)) {
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
player.worldObj.spawnParticle("portal", player.posX + (rand.nextDouble() - 0.5D), player.posY + rand.nextDouble() * player.height - 0.25D,
|
||||
player.posZ + (rand.nextDouble() - 0.5D), (rand.nextDouble() - 0.5D) * 2.0D, -rand.nextDouble(),
|
||||
(rand.nextDouble() - 0.5D) * 2.0D);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public int getRequiredPower(EntityPlayer player, TravelSource source, BlockCoord coord) {
|
||||
@@ -610,9 +612,19 @@ public class TravelController {
|
||||
return TravelSource.BLOCK.maxDistanceTravelledSq;
|
||||
}
|
||||
|
||||
private void sendTravelEvent(BlockCoord bc, TravelSource source, int powerUse, boolean conserveMomentum) {
|
||||
private boolean sendTravelEvent(EntityPlayer player, BlockCoord bc, TravelSource source, int powerUse, boolean conserveMomentum) {
|
||||
|
||||
TeleportEntityEvent evt = new TeleportEntityEvent(player, source, bc.x, bc.y, bc.z);
|
||||
if(MinecraftForge.EVENT_BUS.post(evt)) {
|
||||
return false;
|
||||
}
|
||||
bc.x = evt.targetX;
|
||||
bc.y = evt.targetY;
|
||||
bc.z = evt.targetZ;
|
||||
|
||||
PacketTravelEvent p = new PacketTravelEvent(bc.x, bc.y, bc.z, powerUse, conserveMomentum);
|
||||
PacketHandler.INSTANCE.sendToServer(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
||||
@@ -10,9 +10,9 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public final class BlockCoord {
|
||||
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final int z;
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
|
||||
public BlockCoord(int x, int y, int z) {
|
||||
this.x = x;
|
||||
|
||||
Reference in new issue
Block a user