mirror of
https://github.com/webbukkit/dynmap.git
synced 2025-01-12 19:00:44 +01:00
Merge pull request #3740 from CatMoe/v3.0
Implement sign marker for fabric 1.16
This commit is contained in:
commit
61a377a3ac
@ -27,6 +27,7 @@ import org.dynmap.common.DynmapListenerManager;
|
|||||||
import org.dynmap.common.DynmapPlayer;
|
import org.dynmap.common.DynmapPlayer;
|
||||||
import org.dynmap.common.DynmapServerInterface;
|
import org.dynmap.common.DynmapServerInterface;
|
||||||
import org.dynmap.fabric_1_16_4.event.ServerChatEvents;
|
import org.dynmap.fabric_1_16_4.event.ServerChatEvents;
|
||||||
|
import org.dynmap.fabric_1_16_4.event.BlockEvents;
|
||||||
import org.dynmap.utils.MapChunkCache;
|
import org.dynmap.utils.MapChunkCache;
|
||||||
import org.dynmap.utils.VisibilityLimit;
|
import org.dynmap.utils.VisibilityLimit;
|
||||||
|
|
||||||
@ -283,6 +284,10 @@ public class FabricServer extends DynmapServerInterface {
|
|||||||
}
|
}
|
||||||
}, DynmapPlugin.this);
|
}, DynmapPlugin.this);
|
||||||
*/
|
*/
|
||||||
|
BlockEvents.SIGN_CHANGE_EVENT.register((world, pos, lines, material, player) -> {
|
||||||
|
plugin.core.processSignChange("fabric", FabricWorld.getWorldName(plugin, world),
|
||||||
|
pos.getX(), pos.getY(), pos.getZ(), lines, player.getName().asString());
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -5,6 +5,11 @@ import net.fabricmc.fabric.api.event.EventFactory;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.block.Material;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|
||||||
public class BlockEvents {
|
public class BlockEvents {
|
||||||
private BlockEvents() {
|
private BlockEvents() {
|
||||||
}
|
}
|
||||||
@ -17,7 +22,19 @@ public class BlockEvents {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public static Event<SignChangeCallback> SIGN_CHANGE_EVENT = EventFactory.createArrayBacked(SignChangeCallback.class,
|
||||||
|
(listeners) -> (world, pos, lines, material, player) -> {
|
||||||
|
for (SignChangeCallback callback : listeners) {
|
||||||
|
callback.onSignChange(world, pos, lines, material, player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
public interface BlockCallback {
|
public interface BlockCallback {
|
||||||
void onBlockEvent(World world, BlockPos pos);
|
void onBlockEvent(World world, BlockPos pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface SignChangeCallback {
|
||||||
|
void onSignChange(ServerWorld world, BlockPos pos, String[] lines, Material material, ServerPlayerEntity player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,23 @@ package org.dynmap.fabric_1_16_4.mixin;
|
|||||||
|
|
||||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
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.text.LiteralText;
|
||||||
import org.dynmap.fabric_1_16_4.event.ServerChatEvents;
|
import org.dynmap.fabric_1_16_4.event.ServerChatEvents;
|
||||||
|
import org.dynmap.fabric_1_16_4.event.BlockEvents;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mixin(ServerPlayNetworkHandler.class)
|
@Mixin(ServerPlayNetworkHandler.class)
|
||||||
public abstract class ServerPlayNetworkHandlerMixin {
|
public abstract class ServerPlayNetworkHandlerMixin {
|
||||||
@ -25,4 +36,29 @@ public abstract class ServerPlayNetworkHandlerMixin {
|
|||||||
public void onGameMessage(String string, CallbackInfo info) {
|
public void onGameMessage(String string, CallbackInfo info) {
|
||||||
ServerChatEvents.EVENT.invoker().onChatMessage(player, string);
|
ServerChatEvents.EVENT.invoker().onChatMessage(player, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject(
|
||||||
|
method = "method_31282",
|
||||||
|
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<String> 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);
|
||||||
|
|
||||||
|
// 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