update deps + cleanup

This commit is contained in:
creeper123123321 2022-06-03 17:43:45 -03:00
parent 1b4b940469
commit 086942e267
31 changed files with 66 additions and 212 deletions

View File

@ -1,6 +1,5 @@
// todo migrate this code to kotlin // todo migrate this code to kotlin
import com.google.gson.JsonParser import com.google.gson.JsonParser
import com.modrinth.minotaur.TaskModrinthUpload
import java.nio.file.Files import java.nio.file.Files
import java.util.stream.Collectors import java.util.stream.Collectors
@ -178,8 +177,8 @@ curseforge {
changelog = changelogMsg changelog = changelogMsg
releaseType = "alpha" releaseType = "alpha"
addGameVersion("1.19-Snapshot")
mcReleases.forEach { ver -> addGameVersion(ver) } mcReleases.forEach { ver -> addGameVersion(ver) }
if (!rootProject.curseforge_mc_snapshot.isEmpty()) addGameVersion(rootProject.curseforge_mc_snapshot)
javaVersions.forEach(v -> addGameVersion(v)) javaVersions.forEach(v -> addGameVersion(v))
addGameVersion("Fabric") addGameVersion("Fabric")
@ -213,7 +212,7 @@ modrinth {
uploadFile.set(remapJar) uploadFile.set(remapJar)
List<String> mcs = new ArrayList<>(mcReleases) List<String> mcs = new ArrayList<>(mcReleases)
mcs.add("1.19-pre3") if (!rootProject.modrinth_mc_snapshot.isEmpty()) mcs.add(rootProject.modrinth_mc_snapshot)
gameVersions.set(mcs) gameVersions.set(mcs)
loaders.set(["fabric"]) loaders.set(["fabric"])

View File

@ -4,5 +4,8 @@ org.gradle.jvmargs=-Xms32M -Xmx4G -XX:+UseG1GC -XX:+UseStringDeduplication
org.gradle.parallel=true org.gradle.parallel=true
loader_version=0.14.6 loader_version=0.14.6
viaver_version=4.3.0-1.19-pre3-SNAPSHOT viaver_version=4.3.0-1.19-rc1-SNAPSHOT
yaml_version=1.30 yaml_version=1.30
modrinth_mc_snapshot=1.19-rc1
curseforge_mc_snapshot=1.19-Snapshot

View File

@ -16,6 +16,7 @@ import com.viaversion.viaversion.exception.CancelException;
import com.viaversion.viaversion.protocols.base.BaseProtocol1_16; import com.viaversion.viaversion.protocols.base.BaseProtocol1_16;
import com.viaversion.viaversion.protocols.base.BaseProtocol1_7; import com.viaversion.viaversion.protocols.base.BaseProtocol1_7;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider; import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
import com.viaversion.viaversion.protocols.base.ClientboundStatusPackets;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
@ -124,7 +125,7 @@ public abstract class AbstractFabricVersionProvider extends BaseVersionProvider
&& (blocked || ProtocolUtils.isSupported(serverVer, getVersionForMulticonnect(serverVer)))) { // Intercept the connection && (blocked || ProtocolUtils.isSupported(serverVer, getVersionForMulticonnect(serverVer)))) { // Intercept the connection
int multiconnectSuggestion = blocked ? -1 : getVersionForMulticonnect(serverVer); int multiconnectSuggestion = blocked ? -1 : getVersionForMulticonnect(serverVer);
getLogger().info("Sending " + ProtocolVersion.getProtocol(multiconnectSuggestion) + " for multiconnect version detector"); getLogger().info("Sending " + ProtocolVersion.getProtocol(multiconnectSuggestion) + " for multiconnect version detector");
PacketWrapper newAnswer = PacketWrapper.create(0x00, null, connection); PacketWrapper newAnswer = PacketWrapper.create(ClientboundStatusPackets.STATUS_RESPONSE, null, connection);
newAnswer.write(Type.STRING, "{\"version\":{\"name\":\"viafabric integration\",\"protocol\":" + multiconnectSuggestion + "}}"); newAnswer.write(Type.STRING, "{\"version\":{\"name\":\"viafabric integration\",\"protocol\":" + multiconnectSuggestion + "}}");
newAnswer.send(info.getPipeline().contains(BaseProtocol1_16.class) ? BaseProtocol1_16.class : BaseProtocol1_7.class); newAnswer.send(info.getPipeline().contains(BaseProtocol1_16.class) ? BaseProtocol1_16.class : BaseProtocol1_7.class);
throw CancelException.generate(); throw CancelException.generate();

View File

@ -26,13 +26,17 @@ public class NMSCommandSender implements ViaCommandSender {
return source.hasPermissionLevel(3); return source.hasPermissionLevel(3);
} }
public static Text fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
}
@Override @Override
public void sendMessage(String s) { public void sendMessage(String s) {
if (source instanceof ServerCommandSource) { if (source instanceof ServerCommandSource) {
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false); ((ServerCommandSource) source).sendFeedback(fromLegacy(s), false);
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT } else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT
&& source instanceof ClientCommandSource) { && source instanceof ClientCommandSource) {
MinecraftClient.getInstance().player.addChatMessage(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false); MinecraftClient.getInstance().player.addChatMessage(fromLegacy(s), false);
} }
} }

View File

@ -4,7 +4,6 @@ import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider; import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform; import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc114.ViaFabric; import com.viaversion.fabric.mc114.ViaFabric;
import com.viaversion.fabric.mc114.commands.NMSCommandSender; import com.viaversion.fabric.mc114.commands.NMSCommandSender;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
@ -18,7 +17,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.network.MessageType; import net.minecraft.network.MessageType;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -82,7 +80,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
runServerSync(() -> { runServerSync(() -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return; if (player == null) return;
player.sendChatMessage(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), MessageType.SYSTEM); player.sendChatMessage(NMSCommandSender.fromLegacy(s), MessageType.SYSTEM);
}); });
} }
@ -97,7 +95,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
Supplier<Boolean> kickTask = () -> { Supplier<Boolean> kickTask = () -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return false; if (player == null) return false;
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s))); player.networkHandler.disconnect(NMSCommandSender.fromLegacy(s));
return true; return true;
}; };
if (server.isOnThread()) { if (server.isOnThread()) {

View File

@ -1,6 +1,5 @@
package com.viaversion.fabric.mc114.platform; package com.viaversion.fabric.mc114.platform;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.mc114.providers.VRHandItemProvider; import com.viaversion.fabric.mc114.providers.VRHandItemProvider;
import com.viaversion.fabric.mc114.providers.FabricVersionProvider; import com.viaversion.fabric.mc114.providers.FabricVersionProvider;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
@ -23,7 +22,6 @@ public class VFLoader implements ViaPlatformLoader {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
handProvider.registerClientTick(); handProvider.registerClientTick();
} }
handProvider.registerServerTick();
Via.getManager().getProviders().use(HandItemProvider.class, handProvider); Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
} }
} }

View File

@ -4,33 +4,24 @@ import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc114.ViaFabric; import com.viaversion.fabric.mc114.ViaFabric;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.event.world.WorldTickCallback; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider; import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class VRHandItemProvider extends HandItemProvider { public class VRHandItemProvider extends HandItemProvider {
public Item clientItem = null; public Item clientItem = null;
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
@Override @Override
public Item getHandItem(UserConnection info) { public Item getHandItem(UserConnection info) {
Item serverItem;
if (info.isClientSide()) { if (info.isClientSide()) {
return getClientItem(); return getClientItem();
} else if ((serverItem = serverPlayers.get(info.getProtocolInfo().getUuid())) != null) {
return new DataItem(serverItem);
} }
return super.getHandItem(info); return super.getHandItem(info);
} }
@ -45,24 +36,12 @@ public class VRHandItemProvider extends HandItemProvider {
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public void registerClientTick() { public void registerClientTick() {
try { try {
WorldTickCallback.EVENT.register(world -> { ClientTickEvents.END_CLIENT_TICK.register(world -> tickClient());
if (world.isClient) {
tickClient();
}
});
} catch (NoClassDefFoundError ignored2) { } catch (NoClassDefFoundError ignored2) {
ViaFabric.JLOGGER.info("Fabric Lifecycle V0 isn't installed"); ViaFabric.JLOGGER.info("Fabric Lifecycle V0 isn't installed");
} }
} }
public void registerServerTick() {
WorldTickCallback.EVENT.register(world -> {
if (!world.isClient) {
tickServer(world);
}
});
}
private void tickClient() { private void tickClient() {
ClientPlayerEntity p = MinecraftClient.getInstance().player; ClientPlayerEntity p = MinecraftClient.getInstance().player;
if (p != null) { if (p != null) {
@ -70,12 +49,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
private void tickServer(World world) {
serverPlayers.clear();
world.getPlayers().forEach(it -> serverPlayers
.put(it.getUuid(), fromNative(it.inventory.getMainHandStack())));
}
private Item fromNative(ItemStack original) { private Item fromNative(ItemStack original) {
Identifier iid = Registry.ITEM.getId(original.getItem()); Identifier iid = Registry.ITEM.getId(original.getItem());
int id = RemappingUtil.swordId(iid.toString()); int id = RemappingUtil.swordId(iid.toString());

View File

@ -26,12 +26,16 @@ public class NMSCommandSender implements ViaCommandSender {
return source.hasPermissionLevel(3); return source.hasPermissionLevel(3);
} }
public static Text fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
}
@Override @Override
public void sendMessage(String s) { public void sendMessage(String s) {
if (source instanceof ServerCommandSource) { if (source instanceof ServerCommandSource) {
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false); ((ServerCommandSource) source).sendFeedback(fromLegacy(s), false);
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) { } else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
MinecraftClient.getInstance().player.addChatMessage(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false); MinecraftClient.getInstance().player.addChatMessage(fromLegacy(s), false);
} }
} }

View File

@ -4,7 +4,6 @@ import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider; import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform; import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc115.ViaFabric; import com.viaversion.fabric.mc115.ViaFabric;
import com.viaversion.fabric.mc115.commands.NMSCommandSender; import com.viaversion.fabric.mc115.commands.NMSCommandSender;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
@ -18,7 +17,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.network.MessageType; import net.minecraft.network.MessageType;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -97,7 +95,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
runServerSync(() -> { runServerSync(() -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return; if (player == null) return;
player.sendChatMessage(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), MessageType.SYSTEM); player.sendChatMessage(NMSCommandSender.fromLegacy(s), MessageType.SYSTEM);
}); });
} }
@ -112,7 +110,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
Supplier<Boolean> kickTask = () -> { Supplier<Boolean> kickTask = () -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return false; if (player == null) return false;
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s))); player.networkHandler.disconnect(NMSCommandSender.fromLegacy(s));
return true; return true;
}; };
if (server.isOnThread()) { if (server.isOnThread()) {

View File

@ -1,6 +1,5 @@
package com.viaversion.fabric.mc115.platform; package com.viaversion.fabric.mc115.platform;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.mc115.providers.VRHandItemProvider; import com.viaversion.fabric.mc115.providers.VRHandItemProvider;
import com.viaversion.fabric.mc115.providers.FabricVersionProvider; import com.viaversion.fabric.mc115.providers.FabricVersionProvider;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
@ -23,7 +22,6 @@ public class VFLoader implements ViaPlatformLoader {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
handProvider.registerClientTick(); handProvider.registerClientTick();
} }
handProvider.registerServerTick();
Via.getManager().getProviders().use(HandItemProvider.class, handProvider); Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
} }
} }

View File

@ -9,29 +9,19 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemPr
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class VRHandItemProvider extends HandItemProvider { public class VRHandItemProvider extends HandItemProvider {
public Item clientItem = null; public Item clientItem = null;
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
@Override @Override
public Item getHandItem(UserConnection info) { public Item getHandItem(UserConnection info) {
Item serverItem;
if (info.isClientSide()) { if (info.isClientSide()) {
return getClientItem(); return getClientItem();
} else if ((serverItem = serverPlayers.get(info.getProtocolInfo().getUuid())) != null) {
return new DataItem(serverItem);
} }
return super.getHandItem(info); return super.getHandItem(info);
} }
@ -52,13 +42,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
public void registerServerTick() {
try {
ServerTickEvents.END_WORLD_TICK.register(this::tickServer);
} catch (NoClassDefFoundError ignored) {
}
}
private void tickClient() { private void tickClient() {
ClientPlayerEntity p = MinecraftClient.getInstance().player; ClientPlayerEntity p = MinecraftClient.getInstance().player;
if (p != null) { if (p != null) {
@ -66,12 +49,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
private void tickServer(World world) {
serverPlayers.clear();
world.getPlayers().forEach(it -> serverPlayers
.put(it.getUuid(), fromNative(it.inventory.getMainHandStack())));
}
private Item fromNative(ItemStack original) { private Item fromNative(ItemStack original) {
Identifier iid = Registry.ITEM.getId(original.getItem()); Identifier iid = Registry.ITEM.getId(original.getItem());
int id = RemappingUtil.swordId(iid.toString()); int id = RemappingUtil.swordId(iid.toString());

View File

@ -23,12 +23,16 @@ public class NMSCommandSender implements ViaCommandSender {
return source.hasPermissionLevel(3); return source.hasPermissionLevel(3);
} }
public static Text fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
}
@Override @Override
public void sendMessage(String s) { public void sendMessage(String s) {
if (source instanceof ServerCommandSource) { if (source instanceof ServerCommandSource) {
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false); ((ServerCommandSource) source).sendFeedback(fromLegacy(s), false);
} else if (source instanceof FabricClientCommandSource) { } else if (source instanceof FabricClientCommandSource) {
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s))); ((FabricClientCommandSource) source).sendFeedback(fromLegacy(s));
} }
} }

View File

@ -4,7 +4,6 @@ import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider; import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform; import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc116.ViaFabric; import com.viaversion.fabric.mc116.ViaFabric;
import com.viaversion.fabric.mc116.commands.NMSCommandSender; import com.viaversion.fabric.mc116.commands.NMSCommandSender;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
@ -17,7 +16,6 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -96,9 +94,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
runServerSync(() -> { runServerSync(() -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return; if (player == null) return;
player.sendMessage(Text.Serializer.fromJson( player.sendMessage(NMSCommandSender.fromLegacy(s), false);
RemappingUtil.legacyToJson(s)
), false);
}); });
} }
@ -113,7 +109,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
Supplier<Boolean> kickTask = () -> { Supplier<Boolean> kickTask = () -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return false; if (player == null) return false;
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s))); player.networkHandler.disconnect(NMSCommandSender.fromLegacy(s));
return true; return true;
}; };
if (server.isOnThread()) { if (server.isOnThread()) {

View File

@ -1,6 +1,5 @@
package com.viaversion.fabric.mc116.platform; package com.viaversion.fabric.mc116.platform;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.mc116.providers.VRHandItemProvider; import com.viaversion.fabric.mc116.providers.VRHandItemProvider;
import com.viaversion.fabric.mc116.providers.FabricVersionProvider; import com.viaversion.fabric.mc116.providers.FabricVersionProvider;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
@ -23,7 +22,6 @@ public class VFLoader implements ViaPlatformLoader {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
handProvider.registerClientTick(); handProvider.registerClientTick();
} }
handProvider.registerServerTick();
Via.getManager().getProviders().use(HandItemProvider.class, handProvider); Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
} }
} }

View File

@ -9,29 +9,19 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemPr
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class VRHandItemProvider extends HandItemProvider { public class VRHandItemProvider extends HandItemProvider {
public Item clientItem = null; public Item clientItem = null;
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
@Override @Override
public Item getHandItem(UserConnection info) { public Item getHandItem(UserConnection info) {
Item serverItem;
if (info.isClientSide()) { if (info.isClientSide()) {
return getClientItem(); return getClientItem();
} else if ((serverItem = serverPlayers.get(info.getProtocolInfo().getUuid())) != null) {
return new DataItem(serverItem);
} }
return super.getHandItem(info); return super.getHandItem(info);
} }
@ -52,13 +42,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
public void registerServerTick() {
try {
ServerTickEvents.END_WORLD_TICK.register(this::tickServer);
} catch (NoClassDefFoundError ignored) {
}
}
private void tickClient() { private void tickClient() {
ClientPlayerEntity p = MinecraftClient.getInstance().player; ClientPlayerEntity p = MinecraftClient.getInstance().player;
if (p != null) { if (p != null) {
@ -66,12 +49,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
private void tickServer(World world) {
serverPlayers.clear();
world.getPlayers().forEach(it -> serverPlayers
.put(it.getUuid(), fromNative(it.inventory.getMainHandStack())));
}
private Item fromNative(ItemStack original) { private Item fromNative(ItemStack original) {
Identifier iid = Registry.ITEM.getId(original.getItem()); Identifier iid = Registry.ITEM.getId(original.getItem());
int id = RemappingUtil.swordId(iid.toString()); int id = RemappingUtil.swordId(iid.toString());

View File

@ -1,11 +1,11 @@
package com.viaversion.fabric.mc117.commands; package com.viaversion.fabric.mc117.commands;
import com.viaversion.fabric.common.util.RemappingUtil; import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc117.platform.FabricPlatform;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaCommandSender;
@ -24,12 +24,16 @@ public class NMSCommandSender implements ViaCommandSender {
return source.hasPermissionLevel(3); return source.hasPermissionLevel(3);
} }
public static MutableText fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
}
@Override @Override
public void sendMessage(String s) { public void sendMessage(String s) {
if (source instanceof ServerCommandSource) { if (source instanceof ServerCommandSource) {
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false); ((ServerCommandSource) source).sendFeedback(fromLegacy(s), false);
} else if (source instanceof FabricClientCommandSource) { } else if (source instanceof FabricClientCommandSource) {
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s))); ((FabricClientCommandSource) source).sendFeedback(fromLegacy(s));
} }
} }

View File

@ -4,7 +4,6 @@ import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider; import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform; import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc117.ViaFabric; import com.viaversion.fabric.mc117.ViaFabric;
import com.viaversion.fabric.mc117.commands.NMSCommandSender; import com.viaversion.fabric.mc117.commands.NMSCommandSender;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
@ -17,7 +16,6 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -81,9 +79,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
runServerSync(() -> { runServerSync(() -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return; if (player == null) return;
player.sendMessage(Text.Serializer.fromJson( player.sendMessage(NMSCommandSender.fromLegacy(s), false);
RemappingUtil.legacyToJson(s)
), false);
}); });
} }
@ -98,7 +94,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
Supplier<Boolean> kickTask = () -> { Supplier<Boolean> kickTask = () -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return false; if (player == null) return false;
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s))); player.networkHandler.disconnect(NMSCommandSender.fromLegacy(s));
return true; return true;
}; };
if (server.isOnThread()) { if (server.isOnThread()) {

View File

@ -1,6 +1,5 @@
package com.viaversion.fabric.mc117.platform; package com.viaversion.fabric.mc117.platform;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.mc117.providers.VRHandItemProvider; import com.viaversion.fabric.mc117.providers.VRHandItemProvider;
import com.viaversion.fabric.mc117.providers.FabricVersionProvider; import com.viaversion.fabric.mc117.providers.FabricVersionProvider;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
@ -23,7 +22,6 @@ public class VFLoader implements ViaPlatformLoader {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
handProvider.registerClientTick(); handProvider.registerClientTick();
} }
handProvider.registerServerTick();
Via.getManager().getProviders().use(HandItemProvider.class, handProvider); Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
} }
} }

View File

@ -9,29 +9,19 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemPr
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class VRHandItemProvider extends HandItemProvider { public class VRHandItemProvider extends HandItemProvider {
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
public Item clientItem = null; public Item clientItem = null;
@Override @Override
public Item getHandItem(UserConnection info) { public Item getHandItem(UserConnection info) {
Item serverItem;
if (info.isClientSide()) { if (info.isClientSide()) {
return getClientItem(); return getClientItem();
} else if ((serverItem = serverPlayers.get(info.getProtocolInfo().getUuid())) != null) {
return new DataItem(serverItem);
} }
return super.getHandItem(info); return super.getHandItem(info);
} }
@ -52,13 +42,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
public void registerServerTick() {
try {
ServerTickEvents.END_WORLD_TICK.register(this::tickServer);
} catch (NoClassDefFoundError ignored) {
}
}
private void tickClient() { private void tickClient() {
ClientPlayerEntity p = MinecraftClient.getInstance().player; ClientPlayerEntity p = MinecraftClient.getInstance().player;
if (p != null) { if (p != null) {
@ -66,12 +49,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
private void tickServer(World world) {
serverPlayers.clear();
world.getPlayers().forEach(it -> serverPlayers
.put(it.getUuid(), fromNative(it.getInventory().getMainHandStack())));
}
private Item fromNative(ItemStack original) { private Item fromNative(ItemStack original) {
Identifier iid = Registry.ITEM.getId(original.getItem()); Identifier iid = Registry.ITEM.getId(original.getItem());
int id = RemappingUtil.swordId(iid.toString()); int id = RemappingUtil.swordId(iid.toString());

View File

@ -1,7 +1,6 @@
package com.viaversion.fabric.mc118.commands; package com.viaversion.fabric.mc118.commands;
import com.viaversion.fabric.common.util.RemappingUtil; import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc118.platform.FabricPlatform;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -24,12 +23,16 @@ public class NMSCommandSender implements ViaCommandSender {
return source.hasPermissionLevel(3); return source.hasPermissionLevel(3);
} }
public static Text fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
}
@Override @Override
public void sendMessage(String s) { public void sendMessage(String s) {
if (source instanceof ServerCommandSource) { if (source instanceof ServerCommandSource) {
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false); ((ServerCommandSource) source).sendFeedback(fromLegacy(s), false);
} else if (source instanceof FabricClientCommandSource) { } else if (source instanceof FabricClientCommandSource) {
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s))); ((FabricClientCommandSource) source).sendFeedback(fromLegacy(s));
} }
} }

View File

@ -4,7 +4,6 @@ import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider; import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform; import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc118.ViaFabric; import com.viaversion.fabric.mc118.ViaFabric;
import com.viaversion.fabric.mc118.commands.NMSCommandSender; import com.viaversion.fabric.mc118.commands.NMSCommandSender;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
@ -17,7 +16,6 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -81,9 +79,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
runServerSync(() -> { runServerSync(() -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return; if (player == null) return;
player.sendMessage(Text.Serializer.fromJson( player.sendMessage(NMSCommandSender.fromLegacy(s), false);
RemappingUtil.legacyToJson(s)
), false);
}); });
} }
@ -98,7 +94,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
Supplier<Boolean> kickTask = () -> { Supplier<Boolean> kickTask = () -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return false; if (player == null) return false;
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s))); player.networkHandler.disconnect(NMSCommandSender.fromLegacy(s));
return true; return true;
}; };
if (server.isOnThread()) { if (server.isOnThread()) {

View File

@ -1,6 +1,5 @@
package com.viaversion.fabric.mc118.platform; package com.viaversion.fabric.mc118.platform;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.mc118.providers.VRHandItemProvider; import com.viaversion.fabric.mc118.providers.VRHandItemProvider;
import com.viaversion.fabric.mc118.providers.FabricVersionProvider; import com.viaversion.fabric.mc118.providers.FabricVersionProvider;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
@ -23,7 +22,6 @@ public class VFLoader implements ViaPlatformLoader {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
handProvider.registerClientTick(); handProvider.registerClientTick();
} }
handProvider.registerServerTick();
Via.getManager().getProviders().use(HandItemProvider.class, handProvider); Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
} }
} }

View File

@ -9,29 +9,19 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemPr
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class VRHandItemProvider extends HandItemProvider { public class VRHandItemProvider extends HandItemProvider {
public Item clientItem = null; public Item clientItem = null;
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
@Override @Override
public Item getHandItem(UserConnection info) { public Item getHandItem(UserConnection info) {
Item serverItem;
if (info.isClientSide()) { if (info.isClientSide()) {
return getClientItem(); return getClientItem();
} else if ((serverItem = serverPlayers.get(info.getProtocolInfo().getUuid())) != null) {
return new DataItem(serverItem);
} }
return super.getHandItem(info); return super.getHandItem(info);
} }
@ -52,13 +42,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
public void registerServerTick() {
try {
ServerTickEvents.END_WORLD_TICK.register(this::tickServer);
} catch (NoClassDefFoundError ignored) {
}
}
private void tickClient() { private void tickClient() {
ClientPlayerEntity p = MinecraftClient.getInstance().player; ClientPlayerEntity p = MinecraftClient.getInstance().player;
if (p != null) { if (p != null) {
@ -66,12 +49,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
private void tickServer(World world) {
serverPlayers.clear();
world.getPlayers().forEach(it -> serverPlayers
.put(it.getUuid(), fromNative(it.getInventory().getMainHandStack())));
}
private Item fromNative(ItemStack original) { private Item fromNative(ItemStack original) {
Identifier iid = Registry.ITEM.getId(original.getItem()); Identifier iid = Registry.ITEM.getId(original.getItem());
int id = RemappingUtil.swordId(iid.toString()); int id = RemappingUtil.swordId(iid.toString());

View File

@ -1,7 +1,7 @@
dependencies { dependencies {
minecraft("com.mojang:minecraft:1.19-pre3") minecraft("com.mojang:minecraft:1.19-rc2")
mappings("net.fabricmc:yarn:1.19-pre3+build.4:v2") mappings("net.fabricmc:yarn:1.19-rc2+build.1:v2")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.53.4+1.19") modImplementation("net.fabricmc.fabric-api:fabric-api:0.55.0+1.19")
modImplementation("com.terraformersmc:modmenu:4.0.0-beta.4") modImplementation("com.terraformersmc:modmenu:4.0.0-beta.4")
} }

View File

@ -20,7 +20,7 @@ import io.netty.channel.DefaultEventLoop;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
@ -93,7 +93,7 @@ public class ViaFabric implements ModInitializer {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, env) -> dispatcher.register(command("viaver"))); CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, env) -> dispatcher.register(command("viaver")));
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, env) -> dispatcher.register(command("vvfabric"))); CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, env) -> dispatcher.register(command("vvfabric")));
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
ClientCommandManager.DISPATCHER.register(command("viafabricclient")); ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(command("viafabricclient")));
} }
} catch (NoClassDefFoundError ignored) { } catch (NoClassDefFoundError ignored) {
JLOGGER.info("Couldn't register command as Fabric Commands V1 isn't installed"); JLOGGER.info("Couldn't register command as Fabric Commands V1 isn't installed");

View File

@ -5,6 +5,7 @@ import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import com.viaversion.viaversion.api.command.ViaCommandSender; import com.viaversion.viaversion.api.command.ViaCommandSender;
@ -23,12 +24,16 @@ public class NMSCommandSender implements ViaCommandSender {
return source.hasPermissionLevel(3); return source.hasPermissionLevel(3);
} }
public static MutableText fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
}
@Override @Override
public void sendMessage(String s) { public void sendMessage(String s) {
if (source instanceof ServerCommandSource) { if (source instanceof ServerCommandSource) {
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s)), false); ((ServerCommandSource) source).sendFeedback(fromLegacy(s), false);
} else if (source instanceof FabricClientCommandSource) { } else if (source instanceof FabricClientCommandSource) {
((FabricClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s))); ((FabricClientCommandSource) source).sendFeedback(fromLegacy(s));
} }
} }

View File

@ -4,7 +4,6 @@ import com.viaversion.fabric.common.commands.UserCommandSender;
import com.viaversion.fabric.common.platform.NativeVersionProvider; import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform; import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId; import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc119.ViaFabric; import com.viaversion.fabric.mc119.ViaFabric;
import com.viaversion.fabric.mc119.commands.NMSCommandSender; import com.viaversion.fabric.mc119.commands.NMSCommandSender;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
@ -17,7 +16,6 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -81,9 +79,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
runServerSync(() -> { runServerSync(() -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return; if (player == null) return;
player.sendMessage(Text.Serializer.fromJson( player.sendMessage(NMSCommandSender.fromLegacy(s), false);
RemappingUtil.legacyToJson(s)
), false);
}); });
} }
@ -98,7 +94,7 @@ public class FabricPlatform extends AbstractFabricPlatform {
Supplier<Boolean> kickTask = () -> { Supplier<Boolean> kickTask = () -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return false; if (player == null) return false;
player.networkHandler.disconnect(Text.Serializer.fromJson(RemappingUtil.legacyToJson(s))); player.networkHandler.disconnect(NMSCommandSender.fromLegacy(s));
return true; return true;
}; };
if (server.isOnThread()) { if (server.isOnThread()) {

View File

@ -22,7 +22,6 @@ public class VFLoader implements ViaPlatformLoader {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) { if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
handProvider.registerClientTick(); handProvider.registerClientTick();
} }
handProvider.registerServerTick();
Via.getManager().getProviders().use(HandItemProvider.class, handProvider); Via.getManager().getProviders().use(HandItemProvider.class, handProvider);
} }
} }

View File

@ -9,29 +9,19 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemPr
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class VRHandItemProvider extends HandItemProvider { public class VRHandItemProvider extends HandItemProvider {
public Item clientItem = null; public Item clientItem = null;
public final Map<UUID, Item> serverPlayers = new ConcurrentHashMap<>();
@Override @Override
public Item getHandItem(UserConnection info) { public Item getHandItem(UserConnection info) {
Item serverItem;
if (info.isClientSide()) { if (info.isClientSide()) {
return getClientItem(); return getClientItem();
} else if ((serverItem = serverPlayers.get(info.getProtocolInfo().getUuid())) != null) {
return new DataItem(serverItem);
} }
return super.getHandItem(info); return super.getHandItem(info);
} }
@ -52,13 +42,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
public void registerServerTick() {
try {
ServerTickEvents.END_WORLD_TICK.register(this::tickServer);
} catch (NoClassDefFoundError ignored) {
}
}
private void tickClient() { private void tickClient() {
ClientPlayerEntity p = MinecraftClient.getInstance().player; ClientPlayerEntity p = MinecraftClient.getInstance().player;
if (p != null) { if (p != null) {
@ -66,12 +49,6 @@ public class VRHandItemProvider extends HandItemProvider {
} }
} }
private void tickServer(World world) {
serverPlayers.clear();
world.getPlayers().forEach(it -> serverPlayers
.put(it.getUuid(), fromNative(it.getInventory().getMainHandStack())));
}
private Item fromNative(ItemStack original) { private Item fromNative(ItemStack original) {
Identifier iid = Registry.ITEM.getId(original.getItem()); Identifier iid = Registry.ITEM.getId(original.getItem());
int id = RemappingUtil.swordId(iid.toString()); int id = RemappingUtil.swordId(iid.toString());

View File

@ -8,6 +8,7 @@ dependencies {
} }
// fix newer java // fix newer java
@Suppress("GradlePackageUpdate")
implementation("io.netty:netty-all:4.0.56.Final") implementation("io.netty:netty-all:4.0.56.Final")
} }

View File

@ -1,6 +1,5 @@
package com.viaversion.fabric.mc18.platform; package com.viaversion.fabric.mc18.platform;
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.mc18.providers.VRHandItemProvider; import com.viaversion.fabric.mc18.providers.VRHandItemProvider;
import com.viaversion.fabric.mc18.providers.FabricVersionProvider; import com.viaversion.fabric.mc18.providers.FabricVersionProvider;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;