mirror of
https://github.com/architectury/architectury-api.git
synced 2026-04-02 21:47:40 -05:00
Add ChunkWatchEvent (#464)
Signed-off-by: Sergey Shatunov <me@aur.rocks> Co-authored-by: Max <maxh2709@gmail.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@
|
||||
"client": [
|
||||
],
|
||||
"mixins": [
|
||||
"minecraftforge.MixinChunkMap",
|
||||
"minecraftforge.MixinPlayerChunkSender",
|
||||
"minecraftforge.MixinChunkSerializer",
|
||||
"minecraftforge.MixinEntitySpawnExtension"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user