-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sergey Shatunov <[email protected]>
- Loading branch information
Showing
9 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
common/src/main/java/dev/architectury/event/events/common/ChunkWatchEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* This file is part of architectury. | ||
* Copyright (C) 2020, 2021, 2022 architectury | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package dev.architectury.event.events.common; | ||
|
||
import dev.architectury.event.Event; | ||
import dev.architectury.event.EventFactory; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.level.ChunkPos; | ||
import net.minecraft.world.level.chunk.LevelChunk; | ||
|
||
public interface ChunkWatchEvent { | ||
/** | ||
* This event is fired whenever a {@link ServerPlayer} begins watching a chunk and the chunk is queued up for | ||
* sending to the client. | ||
* <p> | ||
* This event must NOT be used to send additional chunk-related data to the client as the client will not be aware | ||
* of the chunk yet when this event fires. {@link ChunkWatchEvent#SENT} should be used for this purpose instead | ||
*/ | ||
Event<ChunkListener> WATCH = EventFactory.createLoop(); | ||
|
||
/** | ||
* This event is fired whenever a chunk being watched by a {@link ServerPlayer} is transmitted to their client. | ||
* <p> | ||
* This event may be used to send additional chunk-related data to the client. | ||
*/ | ||
Event<ChunkListener> SENT = EventFactory.createLoop(); | ||
|
||
/** | ||
* This event is fired whenever a {@link ServerPlayer} stops watching a chunk. The chunk this event fires for | ||
* may never have actually been known to the client if the chunk goes out of range before being sent due to | ||
* slow pacing of chunk sync on slow connections or to slow clients. | ||
*/ | ||
Event<ChunkPosListener> UNWATCH = EventFactory.createLoop(); | ||
|
||
@FunctionalInterface | ||
interface ChunkListener { | ||
void listen(LevelChunk chunk, ServerLevel level, ServerPlayer player); | ||
} | ||
|
||
@FunctionalInterface | ||
interface ChunkPosListener { | ||
void listen(ChunkPos chunkPos, ServerLevel level, ServerPlayer player); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
fabric/src/main/java/dev/architectury/mixin/fabric/MixinPlayerChunkSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file is part of architectury. | ||
* Copyright (C) 2020, 2021, 2022 architectury | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package dev.architectury.mixin.fabric; | ||
|
||
import dev.architectury.event.events.common.ChunkWatchEvent; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.network.PlayerChunkSender; | ||
import net.minecraft.server.network.ServerGamePacketListenerImpl; | ||
import net.minecraft.world.level.chunk.LevelChunk; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(PlayerChunkSender.class) | ||
public class MixinPlayerChunkSender { | ||
@Inject(method = "sendChunk", at = @At("TAIL")) | ||
private static void send(ServerGamePacketListenerImpl packetListener, ServerLevel level, LevelChunk chunk, CallbackInfo ci) { | ||
ChunkWatchEvent.SENT.invoker().listen(chunk, level, packetListener.player); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
minecraftforge/src/main/java/dev/architectury/mixin/forge/minecraftforge/MixinChunkMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* This file is part of architectury. | ||
* Copyright (C) 2020, 2021, 2022 architectury | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package dev.architectury.mixin.forge.minecraftforge; | ||
|
||
import dev.architectury.event.events.common.ChunkWatchEvent; | ||
import net.minecraft.server.level.ChunkMap; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.level.ChunkPos; | ||
import net.minecraft.world.level.chunk.LevelChunk; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ChunkMap.class) | ||
public abstract class MixinChunkMap { | ||
@Inject(method = "markChunkPendingToSend(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/chunk/LevelChunk;)V", at = @At("TAIL")) | ||
private static void watch(ServerPlayer player, LevelChunk chunk, CallbackInfo ci) { | ||
ChunkWatchEvent.WATCH.invoker().listen(chunk, player.serverLevel(), player); | ||
} | ||
|
||
@Inject(method = "dropChunk(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/ChunkPos;)V", at = @At("HEAD")) | ||
private static void unwatch(ServerPlayer player, ChunkPos chunkPos, CallbackInfo ci) { | ||
ChunkWatchEvent.UNWATCH.invoker().listen(chunkPos, player.serverLevel(), player); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...rge/src/main/java/dev/architectury/mixin/forge/minecraftforge/MixinPlayerChunkSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file is part of architectury. | ||
* Copyright (C) 2020, 2021, 2022 architectury | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package dev.architectury.mixin.forge.minecraftforge; | ||
|
||
import dev.architectury.event.events.common.ChunkWatchEvent; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.network.PlayerChunkSender; | ||
import net.minecraft.server.network.ServerGamePacketListenerImpl; | ||
import net.minecraft.world.level.chunk.LevelChunk; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(PlayerChunkSender.class) | ||
public abstract class MixinPlayerChunkSender { | ||
@Inject(method = "sendChunk", at = @At("TAIL")) | ||
private static void sendChunk(ServerGamePacketListenerImpl packetListener, ServerLevel level, LevelChunk chunk, CallbackInfo ci) { | ||
ChunkWatchEvent.SENT.invoker().listen(chunk, level, packetListener.player); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters