fabric-1.19: do the actual porting work

This commit is contained in:
Kosma Moczek 2022-05-29 13:26:51 +02:00
parent 556051dc9a
commit f02a73bb0d
7 changed files with 34 additions and 21 deletions

View File

@ -268,7 +268,7 @@ public class DynmapPlugin {
}
// TODO: Consider whether cheats are enabled for integrated server
return server.isSingleplayer() && player.equalsIgnoreCase(server.getSinglePlayerName());
return server.isSingleplayer() && server.isHost(server.getPlayerManager().getPlayer(player).getGameProfile());
}
boolean hasPerm(PlayerEntity psender, String permission) {

View File

@ -25,7 +25,7 @@ public class FabricCommandSender implements DynmapCommandSender {
@Override
public void sendMessage(String msg) {
if (sender != null) {
Text ichatcomponent = new LiteralTextContent(msg);
Text ichatcomponent = Text.literal(msg);
sender.sendFeedback(ichatcomponent, false);
}
}

View File

@ -83,7 +83,8 @@ public class FabricMapChunkCache extends GenericMapChunkCache {
ThreadedAnvilChunkStorage acl = cps.threadedAnvilChunkStorage;
ChunkPos coord = new ChunkPos(x, z);
return acl.getNbt(coord);
// Async chunk reading is synchronized here. Perhaps we can do async and improve performance?
return acl.getNbt(coord).join().orElse(null);
} catch (Exception exc) {
Log.severe(String.format("Error reading chunk: %s,%d,%d", dw.getName(), x, z), exc);
return null;

View File

@ -188,8 +188,8 @@ public class FabricPlayer extends FabricCommandSender implements DynmapPlayer {
@Override
public void sendMessage(String msg) {
Text ichatcomponent = new LiteralTextContent(msg);
player.sendSystemMessage(ichatcomponent, Util.NIL_UUID);
Text ichatcomponent = Text.literal(msg);
player.sendMessage(ichatcomponent);
}
@Override
@ -239,12 +239,12 @@ public class FabricPlayer extends FabricCommandSender implements DynmapPlayer {
TitleFadeS2CPacket times = new TitleFadeS2CPacket(fadeInTicks, stayTicks, fadeOutTicks);
player.networkHandler.sendPacket(times);
if (title != null) {
TitleS2CPacket titlepkt = new TitleS2CPacket(new LiteralTextContent(title));
TitleS2CPacket titlepkt = new TitleS2CPacket(Text.literal(title));
player.networkHandler.sendPacket(titlepkt);
}
if (subtitle != null) {
SubtitleS2CPacket subtitlepkt = new SubtitleS2CPacket(new LiteralTextContent(subtitle));
SubtitleS2CPacket subtitlepkt = new SubtitleS2CPacket(Text.literal(subtitle));
player.networkHandler.sendPacket(subtitlepkt);
}
}

View File

@ -272,7 +272,7 @@ public class FabricServer extends DynmapServerInterface {
case SIGN_CHANGE:
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().getContent());
pos.getX(), pos.getY(), pos.getZ(), lines, player.getName().getString());
});
break;
@ -292,8 +292,8 @@ public class FabricServer extends DynmapServerInterface {
@Override
public void broadcastMessage(String msg) {
Text component = new LiteralTextContent(msg);
server.getPlayerManager().broadcast(component, MessageType.SYSTEM, Util.NIL_UUID);
Text component = Text.literal(msg);
server.getPlayerManager().broadcast(component, MessageType.SYSTEM);
Log.info(stripChatColor(msg));
}

View File

@ -1,6 +1,7 @@
package org.dynmap.fabric_1_19;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.Heightmap;
import net.minecraft.world.LightType;
@ -49,7 +50,7 @@ public class FabricWorld extends DynmapWorld {
}
public void updateWorld(World w) {
this.updateWorldHeights(w.getHeight(), w.getDimension().getMinimumY(), w.getSeaLevel());
this.updateWorldHeights(w.getHeight(), w.getBottomY(), w.getSeaLevel());
}
public FabricWorld(DynmapPlugin plugin, World w) {
@ -58,7 +59,7 @@ public class FabricWorld extends DynmapWorld {
w.getRegistryKey() == World.NETHER,
w.getRegistryKey() == World.END,
w.getRegistryKey().getValue().getPath(),
w.getDimension().getMinimumY());
w.getBottomY());
setWorldLoaded(w);
}
@ -148,8 +149,14 @@ public class FabricWorld extends DynmapWorld {
world = w;
this.sealevel = w.getSeaLevel(); // Read actual current sealevel from world
// Update lighting table
for (int i = 0; i < 16; i++) {
this.setBrightnessTableEntry(i, w.getDimension().getBrightness(i));
for (int lightLevel = 0; lightLevel < 16; lightLevel++) {
// Algorithm based on LightmapTextureManager.getBrightness()
// We can't call that method because it's client-only.
// This means the code below can stop being correct if Mojang ever
// updates the curve; in that case we should reflect the changes.
float value = (float) lightLevel / 15.0f;
float brightness = value / (4.0f - 3.0f * value);
this.setBrightnessTableEntry(lightLevel, MathHelper.lerp(w.getDimension().ambientLight(), brightness, 1.0F));
}
}

View File

@ -3,16 +3,21 @@ package org.dynmap.fabric_1_19.mixin;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.network.MessageType;
import net.minecraft.network.encryption.SignedChatMessage;
import net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket;
import net.minecraft.server.filter.Message;
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.LiteralTextContent;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import java.util.List;
import net.minecraft.util.registry.RegistryKey;
import org.dynmap.fabric_1_19.event.BlockEvents;
import org.dynmap.fabric_1_19.event.ServerChatEvents;
import org.spongepowered.asm.mixin.Mixin;
@ -28,15 +33,15 @@ public abstract class ServerPlayNetworkHandlerMixin {
public ServerPlayerEntity player;
@Inject(
method = "handleMessage",
method = "method_44155",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/text/Text;Ljava/util/function/Function;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V",
target = "Lnet/minecraft/server/PlayerManager;broadcast(Lnet/minecraft/server/filter/Message;Lnet/minecraft/server/network/ServerPlayerEntity;Lnet/minecraft/util/registry/RegistryKey;)V",
shift = At.Shift.BEFORE
)
)
public void onGameMessage(TextStream.Message message, CallbackInfo info) {
ServerChatEvents.EVENT.invoker().onChatMessage(player, message.getRaw());
public void onGameMessage(Message<SignedChatMessage> message, CallbackInfo ci) {
ServerChatEvents.EVENT.invoker().onChatMessage(player, message.raw().getContent().getString());
}
@Inject(
@ -48,19 +53,19 @@ public abstract class ServerPlayNetworkHandlerMixin {
),
locals = LocalCapture.CAPTURE_FAILHARD
)
public void onSignUpdate(UpdateSignC2SPacket packet, List<TextStream.Message> signText, CallbackInfo info,
public void onSignUpdate(UpdateSignC2SPacket packet, List<Message<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).getRaw();
rawTexts[i] = signText.get(i).raw();
// 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 LiteralTextContent(rawTexts[i]));
signBlockEntity.setTextOnRow(i, Text.literal(rawTexts[i]));
}
}