From deb5df542e326fdb6a5be22a7f80e6078a401ab6 Mon Sep 17 00:00:00 2001 From: diesieben07 Date: Thu, 29 May 2014 03:33:32 +0200 Subject: [PATCH] Add PlayerEvent.StartTracking and .StopTracking & make trackedEntityIDs visible & Update, as discussed on IRC (squash) --- .../minecraft/entity/EntityTracker.java.patch | 26 +++++++++++++ .../entity/EntityTrackerEntry.java.patch | 17 ++++++++ .../event/ForgeEventFactory.java | 10 +++++ .../event/entity/player/PlayerEvent.java | 39 +++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 patches/minecraft/net/minecraft/entity/EntityTracker.java.patch create mode 100644 patches/minecraft/net/minecraft/entity/EntityTrackerEntry.java.patch diff --git a/patches/minecraft/net/minecraft/entity/EntityTracker.java.patch b/patches/minecraft/net/minecraft/entity/EntityTracker.java.patch new file mode 100644 index 000000000..0945a9e8b --- /dev/null +++ b/patches/minecraft/net/minecraft/entity/EntityTracker.java.patch @@ -0,0 +1,26 @@ +--- ../src-base/minecraft/net/minecraft/entity/EntityTracker.java ++++ ../src-work/minecraft/net/minecraft/entity/EntityTracker.java +@@ -337,4 +337,23 @@ + } + } + } ++ ++ /* ======================================== FORGE START =====================================*/ ++ ++ // don't expose the EntityTrackerEntry directly so mods can't mess with the data in there as easily ++ /** ++ * Get all players tracking the given Entity. The Entity must be part of the World that this Tracker belongs to. ++ * @param entity the Entity ++ * @return all players tracking the Entity ++ */ ++ public Set getTrackingPlayers(Entity entity) ++ { ++ EntityTrackerEntry entry = (EntityTrackerEntry) field_72794_c.func_76041_a(entity.func_145782_y()); ++ if (entry == null) ++ return java.util.Collections.emptySet(); ++ else ++ return java.util.Collections.unmodifiableSet(entry.field_73134_o); ++ } ++ ++ /* ======================================== FORGE END =====================================*/ + } diff --git a/patches/minecraft/net/minecraft/entity/EntityTrackerEntry.java.patch b/patches/minecraft/net/minecraft/entity/EntityTrackerEntry.java.patch new file mode 100644 index 000000000..c919489e6 --- /dev/null +++ b/patches/minecraft/net/minecraft/entity/EntityTrackerEntry.java.patch @@ -0,0 +1,17 @@ +--- ../src-base/minecraft/net/minecraft/entity/EntityTrackerEntry.java ++++ ../src-work/minecraft/net/minecraft/entity/EntityTrackerEntry.java +@@ -436,12 +436,14 @@ + p_73117_1_.field_71135_a.func_147359_a(new S1DPacketEntityEffect(this.field_73132_a.func_145782_y(), potioneffect)); + } + } ++ net.minecraftforge.event.ForgeEventFactory.onStartEntityTracking(field_73132_a, p_73117_1_); + } + } + else if (this.field_73134_o.contains(p_73117_1_)) + { + this.field_73134_o.remove(p_73117_1_); + p_73117_1_.field_71130_g.add(Integer.valueOf(this.field_73132_a.func_145782_y())); ++ net.minecraftforge.event.ForgeEventFactory.onStopEntityTracking(field_73132_a, p_73117_1_); + } + } + } diff --git a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java index e402c6288..1110d00cf 100644 --- a/src/main/java/net/minecraftforge/event/ForgeEventFactory.java +++ b/src/main/java/net/minecraftforge/event/ForgeEventFactory.java @@ -155,4 +155,14 @@ public class ForgeEventFactory MinecraftForge.EVENT_BUS.post(event); return event.result; } + + public static void onStartEntityTracking(Entity entity, EntityPlayer player) + { + MinecraftForge.EVENT_BUS.post(new PlayerEvent.StartTracking(player, entity)); + } + + public static void onStopEntityTracking(Entity entity, EntityPlayer player) + { + MinecraftForge.EVENT_BUS.post(new PlayerEvent.StopTracking(player, entity)); + } } diff --git a/src/main/java/net/minecraftforge/event/entity/player/PlayerEvent.java b/src/main/java/net/minecraftforge/event/entity/player/PlayerEvent.java index 9feb50318..68c60a649 100644 --- a/src/main/java/net/minecraftforge/event/entity/player/PlayerEvent.java +++ b/src/main/java/net/minecraftforge/event/entity/player/PlayerEvent.java @@ -2,6 +2,7 @@ package net.minecraftforge.event.entity.player; import cpw.mods.fml.common.eventhandler.Cancelable; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.event.entity.living.LivingEvent; @@ -92,4 +93,42 @@ public class PlayerEvent extends LivingEvent this.wasDeath = wasDeath; } } + + /** + * Fired when an Entity is started to be "tracked" by this player (the player receives updates about this entity, e.g. motion). + * + */ + public static class StartTracking extends PlayerEvent { + + /** + * The Entity now being tracked. + */ + public final Entity target; + + public StartTracking(EntityPlayer player, Entity target) + { + super(player); + this.target = target; + } + + } + + /** + * Fired when an Entity is stopped to be "tracked" by this player (the player no longer receives updates about this entity, e.g. motion). + * + */ + public static class StopTracking extends PlayerEvent { + + /** + * The Entity no longer being tracked. + */ + public final Entity target; + + public StopTracking(EntityPlayer player, Entity target) + { + super(player); + this.target = target; + } + + } }