Added chunk instance to ChunkWatchEvent (#4805)

This commit is contained in:
TheCyberBrick 2018-04-01 09:07:01 +02:00 committed by LexManos
parent 1fcff02b67
commit 11e623bf4d
3 changed files with 81 additions and 5 deletions

View file

@ -28,7 +28,7 @@
{
this.func_187278_c(p_187276_1_);
+ // chunk watch event - the chunk is ready
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.Watch(this.field_187284_d, p_187276_1_));
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.Watch(this.field_187286_f, p_187276_1_));
}
}
}
@ -57,7 +57,7 @@
this.field_187283_c.remove(p_187277_1_);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.UnWatch(this.field_187284_d, p_187277_1_));
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.UnWatch(this.field_187286_f, p_187277_1_));
+
if (this.field_187283_c.isEmpty())
{
@ -82,7 +82,7 @@
entityplayermp.field_71135_a.func_147359_a(packet);
this.field_187282_b.func_72688_a().func_73039_n().func_85172_a(entityplayermp, this.field_187286_f);
+ // chunk watch event - delayed to here as the chunk wasn't ready in addPlayer
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.Watch(this.field_187284_d, entityplayermp));
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.Watch(this.field_187286_f, entityplayermp));
}
return true;

View file

@ -23,30 +23,49 @@ import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
import net.minecraftforge.fml.common.eventhandler.Event;
import javax.annotation.Nullable;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
/**
* ChunkWatchEvent is fired when an event involving a chunk being watched occurs.<br>
* If a method utilizes this {@link Event} as its parameter, the method will
* receive every child event of this class.<br>
* <br>
* {@link #chunk} contains the ChunkCoordIntPair of the Chunk this event is affecting.<br>
* {@link #chunk} contains the ChunkPos of the Chunk this event is affecting.<br>
* {@link #player} contains the EntityPlayer that is involved with this chunk being watched. <br>
* {@link #chunkInstance} contains the instance of the Chunk. <br>
* <br>
* The {@link #player}'s world may not be the same as the world of the chunk
* when the player is teleporting to another dimension.<br>
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class ChunkWatchEvent extends Event
public class ChunkWatchEvent extends Event //TODO: extend ChunkEvent in 1.13
{
@Deprecated //TODO: Remove in 1.13
private final ChunkPos chunk;
private final EntityPlayerMP player;
private final Chunk chunkInstance;
@Deprecated //TODO: Remove in 1.13
public ChunkWatchEvent(ChunkPos chunk, EntityPlayerMP player)
{
this.chunk = chunk;
this.player = player;
this.chunkInstance = null;
}
public ChunkWatchEvent(Chunk chunk, EntityPlayerMP player)
{
this.chunk = chunk.getPos();
this.player = player;
this.chunkInstance = chunk;
}
@Deprecated //TODO: Remove in 1.13
public ChunkPos getChunk()
{
return chunk;
@ -57,6 +76,16 @@ public class ChunkWatchEvent extends Event
return player;
}
/**
* The affected chunk.
* @return The affected chunk.
*/
@Nullable
public Chunk getChunkInstance()
{
return chunkInstance;
}
/**
* ChunkWatchEvent.Watch is fired when an EntityPlayer begins watching a chunk.<br>
* This event is fired when a chunk is added to the watched chunks of an EntityPlayer in
@ -70,7 +99,10 @@ public class ChunkWatchEvent extends Event
**/
public static class Watch extends ChunkWatchEvent
{
@Deprecated //TODO: Remove in 1.13
public Watch(ChunkPos chunk, EntityPlayerMP player) { super(chunk, player); }
public Watch(Chunk chunk, EntityPlayerMP player) { super(chunk, player); }
}
/**
@ -86,6 +118,9 @@ public class ChunkWatchEvent extends Event
**/
public static class UnWatch extends ChunkWatchEvent
{
@Deprecated //TODO: Remove in 1.13
public UnWatch(ChunkPos chunkLocation, EntityPlayerMP player) { super(chunkLocation, player); }
public UnWatch(Chunk chunk, EntityPlayerMP player) { super(chunk, player); }
}
}

View file

@ -0,0 +1,41 @@
package net.minecraftforge.debug;
import org.apache.logging.log4j.Logger;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod(modid = ChunkWatchWorldTest.MODID, name = "Chunk Watch World Test", version = "1.0", acceptableRemoteVersions = "*")
public class ChunkWatchWorldTest
{
public static final String MODID = "chunkwatchworldtest";
private static final boolean ENABLED = false;
private static Logger logger;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
logger = event.getModLog();
if (ENABLED)
{
MinecraftForge.EVENT_BUS.register(ChunkWatchWorldTest.class);
}
}
@SubscribeEvent
public static void onUnwatch(ChunkWatchEvent.UnWatch event)
{
logger.info("Unwatching chunk {} in dimension {}. Player's dimension: {} ", event.getChunk(), event.getChunkInstance().getWorld().provider.getDimension(), event.getPlayer().getEntityWorld().provider.getDimension());
}
@SubscribeEvent
public static void onWatch(ChunkWatchEvent.Watch event)
{
logger.info("Watching chunk {} in dimension {}. Player's dimension: {} ", event.getChunk(), event.getChunkInstance().getWorld().provider.getDimension(), event.getPlayer().getEntityWorld().provider.getDimension());
}
}