19w06a, separate server and client-side versions

This commit is contained in:
creeper123123321 2019-02-10 07:34:32 -02:00
parent 07ffb40535
commit 13197fb4a0
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
12 changed files with 83 additions and 58 deletions

View File

@ -32,16 +32,15 @@ processResources {
dependencies {
compile "us.myles:viaversion:2.0.0-19w04a"
compile "us.myles:viaversion:2.0.0-19w06a"
compile "de.gerrygames:viarewind-all:1.4.0"
minecraft "com.mojang:minecraft:19w05a"
mappings "net.fabricmc:yarn:19w05a.6"
minecraft "com.mojang:minecraft:19w06a"
mappings "net.fabricmc:yarn:19w06a.3"
modCompile "net.fabricmc:fabric-loader:0.3.5.106"
// Fabric API. This is technically optional, but you probably want it anyway.
modCompile "net.fabricmc:fabric:0.1.5.88"
modCompile "net.fabricmc:fabric:0.2.0.89"
modCompile "io.github.cottonmc:client-commands:0.1.0+19w05a-SNAPSHOT"
}

View File

@ -36,14 +36,11 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import io.github.cottonmc.clientcommands.ArgumentBuilders;
import io.github.cottonmc.clientcommands.ClientCommands;
import net.fabricmc.api.EnvType;
import net.fabricmc.fabric.commands.CommandRegistry;
import net.fabricmc.fabric.events.ServerEvent;
import net.fabricmc.fabric.api.registry.CommandRegistry;
import net.fabricmc.loader.FabricLoader;
import net.minecraft.server.command.ServerCommandSource;
import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
@ -51,28 +48,14 @@ import java.util.Collections;
public class VRViaVersionInitializer {
public static void init() {
ViaFabric.EVENT_LOOP.submit(() -> {
Via.init(ViaManager.builder()
.injector(new VRInjector())
.loader(new VRLoader())
.commandHandler(new VRCommandHandler())
.platform(new VRPlatform()).build());
Via.getManager().init();
ProtocolRegistry.registerProtocol(new Protocol1_7_6_10to1_7_1_5(), Collections.singletonList(ProtocolVersion.v1_7_6.getId()), ProtocolVersion.v1_7_1.getId());
ProtocolRegistry.registerProtocol(new Protocol1_8TO1_7_6_10(), Collections.singletonList(ProtocolVersion.v1_8.getId()), ProtocolVersion.v1_7_6.getId());
ProtocolRegistry.registerProtocol(new Protocol() {
@Override
protected void registerPackets() {
}
@Override
public void init(UserConnection userConnection) {
}
}, Collections.singletonList(459), 458); // todo remove test
});
Via.init(ViaManager.builder()
.injector(new VRInjector())
.loader(new VRLoader())
.commandHandler(new VRCommandHandler())
.platform(new VRPlatform()).build());
Via.getManager().init();
ProtocolRegistry.registerProtocol(new Protocol1_7_6_10to1_7_1_5(), Collections.singletonList(ProtocolVersion.v1_7_6.getId()), ProtocolVersion.v1_7_1.getId());
ProtocolRegistry.registerProtocol(new Protocol1_8TO1_7_6_10(), Collections.singletonList(ProtocolVersion.v1_8.getId()), ProtocolVersion.v1_7_6.getId());
if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT) {
ClientCommands.registerCommand(command -> command
@ -101,13 +84,5 @@ public class VRViaVersionInitializer {
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute)
)
);
ServerEvent.START.register(server -> {
try {
ProtocolRegistry.SERVER_PROTOCOL = Via.getManager().getInjector().getServerProtocolVersion();
} catch (Exception e) {
e.printStackTrace();
}
});
}
}

View File

@ -132,7 +132,7 @@ public class ViaFabric implements ModInitializer {
public void onInitialize() {
File viaVersionJar = FabricLoader.INSTANCE.getConfigDirectory().toPath().resolve("ViaFabric").resolve("viaversion.jar").toFile();
try {
checkForUpdates(viaVersionJar, "viaversion", "us/myles", "");
checkForUpdates(viaVersionJar, "viaversion", "us/myles", "ViaVersion");
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -40,7 +40,7 @@ public class UserCommandSender implements ViaCommandSender {
@Override
public boolean hasPermission(String s) {
return true;
return false;
}
@Override

View File

@ -24,10 +24,13 @@
package com.github.creeper123123321.viafabric.gui.multiplayer;
import com.github.creeper123123321.viafabric.providers.VRVersionProvider;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.protocols.base.VersionProvider;
public class SaveProtocolButton extends ButtonWidget {
private TextFieldWidget textField;
@ -40,16 +43,18 @@ public class SaveProtocolButton extends ButtonWidget {
@Override
public void onPressed(double p_mouseClicked_1_, double p_mouseClicked_3_) {
super.onPressed(p_mouseClicked_1_, p_mouseClicked_3_);
int newVersion = ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion;
try {
ProtocolRegistry.SERVER_PROTOCOL = Integer.parseInt(textField.getText());
newVersion = Integer.parseInt(textField.getText());
} catch (NumberFormatException e) {
try {
ProtocolRegistry.SERVER_PROTOCOL = ProtocolVersion.getClosest(textField.getText()).getId();
newVersion = ProtocolVersion.getClosest(textField.getText()).getId();
} catch (NullPointerException ignored) {
}
}
textField.setText(ProtocolVersion.isRegistered(ProtocolRegistry.SERVER_PROTOCOL)
? ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL).getName()
: Integer.toString(ProtocolRegistry.SERVER_PROTOCOL));
((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion = newVersion;
textField.setText(ProtocolVersion.isRegistered(newVersion)
? ProtocolVersion.getProtocol(newVersion).getName()
: Integer.toString(newVersion));
}
}

View File

@ -26,7 +26,7 @@ package com.github.creeper123123321.viafabric.mixin;
import com.github.creeper123123321.viafabric.handler.serverside.FabricDecodeHandler;
import com.github.creeper123123321.viafabric.handler.serverside.FabricEncodeHandler;
import com.github.creeper123123321.viafabric.protocol.ClientSideInterceptor;
import com.github.creeper123123321.viafabric.protocol.ClientSideReference;
import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder;
@ -44,7 +44,7 @@ public class MixinClientConnectionServerChInit {
private void onInitChannel(Channel channel, CallbackInfo ci) {
if (channel instanceof SocketChannel) {
UserConnection user = new UserConnection(channel);
new ProtocolPipeline(user).add(new ClientSideInterceptor());
new ProtocolPipeline(user).add(new ClientSideReference());
MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder");
ByteToMessageDecoder oldDecoder = (ByteToMessageDecoder) channel.pipeline().get("decoder");

View File

@ -27,7 +27,7 @@ package com.github.creeper123123321.viafabric.mixin.client;
import com.github.creeper123123321.viafabric.handler.clientside.VRDecodeHandler;
import com.github.creeper123123321.viafabric.handler.clientside.VREncodeHandler;
import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection;
import com.github.creeper123123321.viafabric.protocol.ClientSideInterceptor;
import com.github.creeper123123321.viafabric.protocol.ClientSideReference;
import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder;
@ -45,7 +45,7 @@ public class MixinClientConnectionChInit {
private void onInitChannel(Channel channel, CallbackInfo ci) {
if (channel instanceof SocketChannel) {
UserConnection user = new VRClientSideUserConnection(channel);
new ProtocolPipeline(user).add(new ClientSideInterceptor());
new ProtocolPipeline(user).add(new ClientSideReference());
MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder");
ByteToMessageDecoder oldDecoder = (ByteToMessageDecoder) channel.pipeline().get("decoder");

View File

@ -25,6 +25,7 @@
package com.github.creeper123123321.viafabric.mixin.client;
import com.github.creeper123123321.viafabric.gui.multiplayer.SaveProtocolButton;
import com.github.creeper123123321.viafabric.providers.VRVersionProvider;
import com.github.creeper123123321.viafabric.util.VersionFormatFilter;
import net.minecraft.client.gui.GuiEventListener;
import net.minecraft.client.gui.Screen;
@ -36,8 +37,10 @@ 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.CallbackInfoReturnable;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.protocols.base.VersionProvider;
@Mixin(MultiplayerScreen.class)
public abstract class MixinMultiplayerGui extends Screen {
@ -46,9 +49,10 @@ public abstract class MixinMultiplayerGui extends Screen {
@Inject(method = "onInitialized", at = @At("TAIL"))
private void onOnInitialized(CallbackInfo ci) {
protocolVersion = new TextFieldWidget(1235, fontRenderer, this.width / 2 + 55, 8, 45, 20);
protocolVersion.setText(ProtocolVersion.isRegistered(ProtocolRegistry.SERVER_PROTOCOL)
? ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL).getName()
: Integer.toString(ProtocolRegistry.SERVER_PROTOCOL));
int clientSideVersion = ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion;
protocolVersion.setText(ProtocolVersion.isRegistered(clientSideVersion)
? ProtocolVersion.getProtocol(clientSideVersion).getName()
: Integer.toString(clientSideVersion));
protocolVersion.method_1890(new VersionFormatFilter());
this.listeners.add(protocolVersion);
addButton(new SaveProtocolButton(6356, width / 2 + 100, 8, 50, 20,

View File

@ -24,15 +24,18 @@
package com.github.creeper123123321.viafabric.platform;
import com.github.creeper123123321.viafabric.providers.VRVersionProvider;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter;
import us.myles.ViaVersion.protocols.base.VersionProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
public class VRLoader implements ViaPlatformLoader {
@Override
public void load() {
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
Via.getManager().getProviders().use(VersionProvider.class, new VRVersionProvider());
}
@Override

View File

@ -27,7 +27,7 @@ package com.github.creeper123123321.viafabric.platform;
import com.github.creeper123123321.viafabric.ViaFabric;
import com.github.creeper123123321.viafabric.commands.NMSCommandSender;
import com.github.creeper123123321.viafabric.commands.UserCommandSender;
import com.github.creeper123123321.viafabric.protocol.ClientSideInterceptor;
import com.github.creeper123123321.viafabric.protocol.ClientSideReference;
import com.github.creeper123123321.viafabric.util.FutureTaskId;
import net.fabricmc.loader.FabricLoader;
import net.fabricmc.loader.ModContainer;
@ -170,7 +170,7 @@ public class VRPlatform implements ViaPlatform {
chat.write(Type.STRING, ChatRewriter.legacyTextToJson(s));
chat.write(Type.BYTE, (byte) 0); // Position chat box
try {
chat.send(ClientSideInterceptor.class);
chat.send(ClientSideReference.class);
} catch (CancelException e) {
// Ignore
} catch (Exception e) {
@ -192,7 +192,7 @@ public class VRPlatform implements ViaPlatform {
PacketWrapper chat = new PacketWrapper(0x1B, null, user);
chat.write(Type.STRING, ChatRewriter.legacyTextToJson(s));
try {
chat.sendFuture(ClientSideInterceptor.class).addListener(future -> user.getChannel().close());
chat.sendFuture(ClientSideReference.class).addListener(future -> user.getChannel().close());
} catch (Exception e) {
e.printStackTrace();
return false;

View File

@ -27,13 +27,12 @@ package com.github.creeper123123321.viafabric.protocol;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
public class ClientSideInterceptor extends Protocol {
public class ClientSideReference extends Protocol {
@Override
protected void registerPackets() {
}
@Override
public void init(UserConnection userConnection) {
}
}

View File

@ -0,0 +1,40 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.creeper123123321.viafabric.providers;
import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection;
import net.minecraft.SharedConstants;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.VersionProvider;
public class VRVersionProvider extends VersionProvider {
public int clientSideModeVersion = SharedConstants.getGameVersion().getProtocolVersion();
@Override
public int getServerProtocol(UserConnection connection) throws Exception {
if (connection instanceof VRClientSideUserConnection) return clientSideModeVersion;
return super.getServerProtocol(connection);
}
}