Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 5ce6d98

Browse files
kitlithTheGlitch76
andauthored
Implement ChunkWatchEvent.UnWatch (#143)
* Implement ChunkWatchEvent.UnWatch NOTE: This implementation follows upstream 1.14.4 Forge, not the commit we're tracking which doesn't implement it at all. * fix error Co-authored-by: Glitch <glitchieproductionsofficial@gmail.com>
1 parent a1cec72 commit 5ce6d98

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

patchwork-events-world/src/main/java/net/minecraftforge/event/world/ChunkWatchEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public Watch(ServerPlayerEntity player, ChunkPos pos, ServerWorld world) {
9191
*
9292
* <p>This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.</p>
9393
*/
94-
/* TODO public static class UnWatch extends ChunkWatchEvent {
94+
public static class UnWatch extends ChunkWatchEvent {
9595
public UnWatch(ServerPlayerEntity player, ChunkPos pos, ServerWorld world) {
9696
super(player, pos, world);
9797
}
98-
}*/
98+
}
9999
}

patchwork-events-world/src/main/java/net/patchworkmc/impl/event/world/WorldEvents.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
2323
import java.util.List;
2424

2525
import net.minecraftforge.common.MinecraftForge;
26+
import net.minecraftforge.event.world.ChunkWatchEvent;
2627
import net.minecraftforge.event.world.WorldEvent;
2728

2829
import net.minecraft.entity.EntityCategory;
30+
import net.minecraft.server.network.ServerPlayerEntity;
31+
import net.minecraft.server.world.ServerWorld;
2932
import net.minecraft.util.math.BlockPos;
33+
import net.minecraft.util.math.ChunkPos;
3034
import net.minecraft.world.IWorld;
3135
import net.minecraft.world.biome.Biome;
3236
import net.minecraft.world.dimension.DimensionType;
@@ -62,6 +66,14 @@ public static void onWorldSave(IWorld world) {
6266
MinecraftForge.EVENT_BUS.post(new WorldEvent.Save(world));
6367
}
6468

69+
public static void fireChunkWatch(boolean watch, ServerPlayerEntity entity, ChunkPos chunkpos, ServerWorld world) {
70+
if (watch) {
71+
MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.Watch(entity, chunkpos, world));
72+
} else {
73+
MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.UnWatch(entity, chunkpos, world));
74+
}
75+
}
76+
6577
@Override
6678
public void onInitialize() {
6779
ServerWorldEvents.LOAD.register((server, world) -> {

patchwork-events-world/src/main/java/net/patchworkmc/mixin/event/world/MixinThreadedAnvilChunkStorage.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
package net.patchworkmc.mixin.event.world;
2121

22-
import net.minecraftforge.common.MinecraftForge;
23-
import net.minecraftforge.event.world.ChunkWatchEvent;
2422
import org.spongepowered.asm.mixin.Mixin;
2523
import org.spongepowered.asm.mixin.Shadow;
2624
import org.spongepowered.asm.mixin.injection.At;
@@ -33,17 +31,17 @@
3331
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
3432
import net.minecraft.util.math.ChunkPos;
3533

34+
import net.patchworkmc.impl.event.world.WorldEvents;
35+
3636
@Mixin(ThreadedAnvilChunkStorage.class)
3737
public class MixinThreadedAnvilChunkStorage {
3838
@Shadow
3939
private ServerWorld world;
4040

4141
@Inject(method = "sendWatchPackets", at = @At("HEAD"))
4242
private void fireWatchEvents(ServerPlayerEntity player, ChunkPos pos, Packet<?>[] packets, boolean withinMaxWatchDistance, boolean withinViewDistance, CallbackInfo callback) {
43-
if (withinViewDistance && !withinMaxWatchDistance) {
44-
ChunkWatchEvent.Watch event = new ChunkWatchEvent.Watch(player, pos, world);
45-
46-
MinecraftForge.EVENT_BUS.post(event);
43+
if (this.world == player.world && withinMaxWatchDistance != withinViewDistance) {
44+
WorldEvents.fireChunkWatch(withinViewDistance, player, pos, this.world);
4745
}
4846
}
4947
}

0 commit comments

Comments
 (0)