Fixed ChunkWatchEvent.(Un)Watch not firing correctly (#6453)

This commit is contained in:
malte0811 2020-02-14 21:02:47 +01:00 committed by GitHub
parent 886e89ccb2
commit 3f292d5d42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 27 deletions

View file

@ -40,11 +40,11 @@
this.func_219100_a(chunkpos, compoundnbt1);
return true;
} catch (Exception exception) {
@@ -815,6 +820,7 @@
for(int l = i - this.field_219247_A; l <= i + this.field_219247_A; ++l) {
for(int k = j - this.field_219247_A; k <= j + this.field_219247_A; ++k) {
ChunkPos chunkpos = new ChunkPos(l, k);
+ net.minecraftforge.event.ForgeEventFactory.fireChunkWatch(p_219234_2_, p_219234_1_, chunkpos, field_219255_i);
this.func_219199_a(p_219234_1_, chunkpos, new IPacket[2], !p_219234_2_, p_219234_2_);
}
}
@@ -711,6 +716,7 @@
protected void func_219199_a(ServerPlayerEntity p_219199_1_, ChunkPos p_219199_2_, IPacket<?>[] p_219199_3_, boolean p_219199_4_, boolean p_219199_5_) {
if (p_219199_1_.field_70170_p == this.field_219255_i) {
+ net.minecraftforge.event.ForgeEventFactory.fireChunkWatch(p_219199_4_, p_219199_5_, p_219199_1_, p_219199_2_, this.field_219255_i);
if (p_219199_5_ && !p_219199_4_) {
ChunkHolder chunkholder = this.func_219219_b(p_219199_2_.func_201841_a());
if (chunkholder != null) {

View file

@ -694,6 +694,12 @@ public class ForgeEventFactory
MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.UnWatch(entity, chunkpos, world));
}
public static void fireChunkWatch(boolean wasLoaded, boolean load, ServerPlayerEntity entity, ChunkPos chunkpos, ServerWorld world)
{
if (wasLoaded != load)
fireChunkWatch(load, entity, chunkpos, world);
}
public static boolean onPistonMovePre(World world, BlockPos pos, Direction direction, boolean extending)
{
return MinecraftForge.EVENT_BUS.post(new PistonEvent.Pre(world, pos, direction, extending ? PistonEvent.PistonMoveType.EXTEND : PistonEvent.PistonMoveType.RETRACT));

View file

@ -29,7 +29,8 @@ import net.minecraftforge.eventbus.api.Event;
* 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 ChunkPos of the Chunk this event is affecting.<br>
* {@link #pos} contains the ChunkPos of the Chunk this event is affecting.<br>
* {@link #world} contains the World of the Chunk this event is affecting.<br>
* {@link #player} contains the EntityPlayer that is involved with this chunk being watched. <br>
* <br>
* The {@link #player}'s world may not be the same as the world of the chunk
@ -68,7 +69,7 @@ public class ChunkWatchEvent extends Event
/**
* 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
* {@link PlayerChunkMapEntry#addPlayer(EntityPlayerMP)} and {@link PlayerChunkMapEntry#sendToPlayers()}. <br>
* {@link net.minecraft.world.server.ChunkManager#setChunkLoadedAtClient}. <br>
* <br>
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
* <br>
@ -84,7 +85,7 @@ public class ChunkWatchEvent extends Event
/**
* ChunkWatchEvent.UnWatch is fired when an EntityPlayer stops watching a chunk.<br>
* This event is fired when a chunk is removed from the watched chunks of an EntityPlayer in
* {@link PlayerChunkMapEntry#removePlayer(EntityPlayerMP)}. <br>
* {@link net.minecraft.world.server.ChunkManager#setChunkLoadedAtClient}. <br>
* <br>
* This event is not {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
* <br>

View file

@ -53,7 +53,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@Mod("gravity_attribute_test")
public class GravityAttributeTest
{
public static final boolean ENABLE = true;
public static final boolean ENABLE = false;
private static Logger logger = LogManager.getLogger();
private int ticks;
private static final UUID REDUCED_GRAVITY_ID = UUID.fromString("DEB06000-7979-4242-8888-00000DEB0600");

View file

@ -17,31 +17,34 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
package net.minecraftforge.debug.world;
import org.apache.logging.log4j.Logger;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
//@Mod(modid = ChunkWatchEventTest.MODID, name = "Chunk Watch Event Test", version = "1.0", acceptableRemoteVersions = "*")
import javax.annotation.Nullable;
import java.util.UUID;
@Mod(ChunkWatchEventTest.MODID)
public class ChunkWatchEventTest
{
public static final String MODID = "chunkwatchworldtest";
private static final boolean ENABLED = false;
private static Logger logger;
private static Object2IntMap<UUID> watchedByPlayer = new Object2IntOpenHashMap<>();
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
public ChunkWatchEventTest()
{
logger = event.getModLog();
logger = LogManager.getLogger();
if (ENABLED)
{
@ -52,13 +55,27 @@ public class ChunkWatchEventTest
@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());
int watched = watchedByPlayer.getInt(event.getPlayer().getUniqueID());
--watched;
watchedByPlayer.put(event.getPlayer().getUniqueID(), watched);
logger.info("Unwatching chunk {} in dimension {}. Player's dimension: {}, total chunks watched by player {}",
event.getPos(), getDimensionName(event.getWorld()), getDimensionName(event.getPlayer().getEntityWorld()),
watched);
}
@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());
int watched = watchedByPlayer.getInt(event.getPlayer().getUniqueID());
++watched;
watchedByPlayer.put(event.getPlayer().getUniqueID(), watched);
logger.info("Watching chunk {} in dimension {}. Player's dimension: {}, total chunks watched by player {}",
event.getPos(), getDimensionName(event.getWorld()), getDimensionName(event.getPlayer().getEntityWorld()),
watched);
}
@Nullable
private static ResourceLocation getDimensionName(World w) {
return w.getDimension().getType().getRegistryName();
}
}
*/

View file

@ -53,7 +53,9 @@ loaderVersion="[28,)"
modId="new_model_loader_test"
[[mods]]
modId="forgedebugmultilayermodel"
[[mods]]
modId="chunkwatchworldtest"
[[mods]]
modId="trsr_transformer_test"
[[mods]]
modId="nameplate_render_test"
modId="nameplate_render_test"