mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-06-28 23:55:04 +02:00
fabric-1.18: add ServerPlayNetworkHandlerMixin.onSignUpdate()
This commit is contained in:
parent
b31d7ebe9d
commit
588525c81f
|
@ -1,14 +1,26 @@
|
|||
package org.dynmap.fabric_1_18.mixin;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket;
|
||||
import net.minecraft.server.filter.TextStream;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.dynmap.fabric_1_18.event.BlockEvents;
|
||||
import org.dynmap.fabric_1_18.event.ServerChatEvents;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
@Mixin(ServerPlayNetworkHandler.class)
|
||||
public abstract class ServerPlayNetworkHandlerMixin {
|
||||
|
@ -26,4 +38,29 @@ public abstract class ServerPlayNetworkHandlerMixin {
|
|||
public void onGameMessage(TextStream.Message message, CallbackInfo info) {
|
||||
ServerChatEvents.EVENT.invoker().onChatMessage(player, message.getRaw());
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "onSignUpdate",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/block/entity/SignBlockEntity;markDirty()V",
|
||||
shift = At.Shift.BEFORE
|
||||
),
|
||||
locals = LocalCapture.CAPTURE_FAILHARD
|
||||
)
|
||||
public void onSignUpdate(UpdateSignC2SPacket packet, List<TextStream.Message> signText, CallbackInfo info,
|
||||
ServerWorld serverWorld, BlockPos blockPos, BlockState blockState, BlockEntity blockEntity, SignBlockEntity signBlockEntity)
|
||||
{
|
||||
// Pull the raw text from the input.
|
||||
String[] rawTexts = new String[4];
|
||||
for (int i=0; i<signText.size(); i++)
|
||||
rawTexts[i] = signText.get(i).getRaw();
|
||||
|
||||
// Fire the event.
|
||||
BlockEvents.SIGN_CHANGE_EVENT.invoker().onSignChange(serverWorld, blockPos, rawTexts, blockState.getMaterial(), player);
|
||||
|
||||
// Put the (possibly updated) texts in the sign. Ignore filtering (is this OK?).
|
||||
for (int i=0; i<signText.size(); i++)
|
||||
signBlockEntity.setTextOnRow(i, new LiteralText(rawTexts[i]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user