Remove ViaRift.fakeServerVersion, use git version, add version detector

This commit is contained in:
creeper123123321 2018-10-07 10:02:28 -03:00
parent 7e1e9f9f4b
commit 66ebce7d47
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
10 changed files with 70 additions and 28 deletions

View File

@ -12,6 +12,7 @@ buildscript {
plugins {
id 'net.minecrell.licenser' version '0.4.1'
id 'com.palantir.git-version' version '0.12.0-rc2'
}
apply plugin: 'net.minecraftforge.gradle.tweaker-client'
@ -19,7 +20,7 @@ apply plugin: 'org.spongepowered.mixin'
apply plugin: 'java'
group 'com.github.creeper123123321.viarift'
version '1.0.1'
version gitVersion()
archivesBaseName = 'ViaRift'
sourceCompatibility = 1.8

View File

@ -34,21 +34,25 @@ import io.netty.channel.EventLoop;
import net.minecraft.util.NamedThreadFactory;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.rift.listener.MinecraftStartListener;
import org.dimdev.riftloader.listener.InitializationListener;
import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.mixin.Mixins;
import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.Via;
public class ViaRift implements InitializationListener {
public static int fakeServerVersion = -1;
public static final Logger LOGGER = LogManager.getLogger();
public class ViaRift implements InitializationListener, MinecraftStartListener {
public static final Logger LOGGER = LogManager.getLogger("ViaRift");
public static final java.util.logging.Logger JLOGGER = new JLoggerToLog4j(LOGGER);
public static final EventLoop EVENT_LOOP = new DefaultEventLoop(new NamedThreadFactory("ViaRift"));
@Override
public void onInitialization() {
MixinBootstrap.init();
Mixins.addConfiguration("mixins.viarift.main.json");
}
@Override
public void onMinecraftStart() {
Via.init(ViaManager.builder()
.injector(new VRInjector())
.loader(new VRLoader())

View File

@ -24,9 +24,9 @@
package com.github.creeper123123321.viarift.gui.multiplayer;
import com.github.creeper123123321.viarift.ViaRift;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
public class SaveProtocolButton extends GuiButton {
private GuiTextField textField;
@ -40,9 +40,9 @@ public class SaveProtocolButton extends GuiButton {
public void mousePressed(double p_mouseClicked_1_, double p_mouseClicked_3_) {
super.mousePressed(p_mouseClicked_1_, p_mouseClicked_3_);
try {
ViaRift.fakeServerVersion = Integer.parseInt(textField.getText());
ProtocolRegistry.SERVER_PROTOCOL = Integer.parseInt(textField.getText());
} catch (NumberFormatException e) {
textField.setText(Integer.toString(ViaRift.fakeServerVersion));
textField.setText(Integer.toString(ProtocolRegistry.SERVER_PROTOCOL));
}
}
}

View File

@ -22,15 +22,8 @@
* SOFTWARE.
*/
package com.github.creeper123123321.viarift.provider;
package com.github.creeper123123321.viarift.interfaces;
import com.github.creeper123123321.viarift.ViaRift;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.VersionProvider;
public class VRVersionProvider extends VersionProvider {
@Override
public int getServerProtocol(UserConnection connection) throws Exception {
return ViaRift.fakeServerVersion;
}
public interface IPatchedCPacketHandshake {
int getProtocolVersion();
}

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.viarift.mixin.client;
import com.github.creeper123123321.viarift.interfaces.IPatchedCPacketHandshake;
import net.minecraft.network.handshake.client.CPacketHandshake;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(CPacketHandshake.class)
public class MixinCPacketHandshake implements IPatchedCPacketHandshake {
@Shadow private int protocolVersion;
@Override
public int getProtocolVersion() {
return protocolVersion;
}
}

View File

@ -24,7 +24,6 @@
package com.github.creeper123123321.viarift.mixin.client;
import com.github.creeper123123321.viarift.ViaRift;
import com.github.creeper123123321.viarift.gui.multiplayer.SaveProtocolButton;
import com.github.creeper123123321.viarift.util.IntegerFormatFilter;
import net.minecraft.client.gui.*;
@ -34,6 +33,7 @@ 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.protocol.ProtocolRegistry;
@Mixin(GuiMultiplayer.class)
public abstract class MixinGuiMultiplayer extends GuiScreen {
@ -43,7 +43,7 @@ public abstract class MixinGuiMultiplayer extends GuiScreen {
@Inject(method = "initGui", at = @At("TAIL"))
private void onInitGui(CallbackInfo ci) {
protocolVersion = new GuiTextField(1235, fontRenderer, this.width / 2 + 70, 8, 30, 20);
protocolVersion.setText(Integer.toString(ViaRift.fakeServerVersion));
protocolVersion.setText(Integer.toString(ProtocolRegistry.SERVER_PROTOCOL));
protocolVersion.func_200675_a(new IntegerFormatFilter());
this.eventListeners.add(protocolVersion);
saveProtocol = new SaveProtocolButton(6356, width / 2 + 100, 8, 50, 20,

View File

@ -24,23 +24,29 @@
package com.github.creeper123123321.viarift.platform;
import com.github.creeper123123321.viarift.ViaRift;
import com.github.creeper123123321.viarift.interfaces.IPatchedCPacketHandshake;
import net.minecraft.network.EnumConnectionState;
import net.minecraft.network.handshake.client.CPacketHandshake;
import us.myles.ViaVersion.api.platform.ViaInjector;
public class VRInjector implements ViaInjector {
@Override
public void inject() throws Exception {
public void inject() {
// *looks at Mixins*
}
@Override
public void uninject() throws Exception {
public void uninject() {
// not possible *plays sad violin*
}
@Override
public int getServerProtocolVersion() throws Exception {
return ViaRift.fakeServerVersion;
public int getServerProtocolVersion() {
return ((IPatchedCPacketHandshake) new CPacketHandshake(
"XGH to get protocol",
0,
EnumConnectionState.HANDSHAKING)
).getProtocolVersion();
}
@Override

View File

@ -24,17 +24,14 @@
package com.github.creeper123123321.viarift.platform;
import com.github.creeper123123321.viarift.provider.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(VersionProvider.class, new VRVersionProvider());
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
}

View File

@ -9,6 +9,7 @@
"MixinNetworkManagerClientChInit"
],
"client": [
"client.MixinGuiMultiplayer"
"client.MixinGuiMultiplayer",
"client.MixinCPacketHandshake"
]
}