mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-21 11:35:16 +01:00
1.8, GUI for protocol
This commit is contained in:
parent
274b80a682
commit
edfd826b02
@ -63,7 +63,7 @@ mixin {
|
||||
|
||||
minecraft {
|
||||
version = '1.13'
|
||||
mappings = 'snapshot_3'
|
||||
mappings = 'snapshot_5'
|
||||
runDir = 'run'
|
||||
tweakClass = 'org.dimdev.riftloader.launch.RiftLoaderTweaker'
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import us.myles.ViaVersion.ViaManager;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
public class ViaRift implements InitializationListener {
|
||||
public static int fakeServerVersion = 340; // TODO
|
||||
public static int fakeServerVersion = 393; // TODO
|
||||
@Override
|
||||
public void onInitialization() {
|
||||
MixinBootstrap.init();
|
||||
|
@ -0,0 +1,23 @@
|
||||
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;
|
||||
|
||||
public class SaveProtocolButton extends GuiButton {
|
||||
private GuiTextField textField;
|
||||
|
||||
public SaveProtocolButton(int id, int x, int y, int width, int height, String text, GuiTextField tf) {
|
||||
super(id, x, y, width, height, text);
|
||||
textField = tf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(double p_mouseClicked_1_, double p_mouseClicked_3_) {
|
||||
try {
|
||||
ViaRift.fakeServerVersion = Integer.parseInt(textField.getText());
|
||||
} catch (NumberFormatException e) {
|
||||
textField.setText(Integer.toString(ViaRift.fakeServerVersion));
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.exception.CancelException;
|
||||
|
@ -0,0 +1,53 @@
|
||||
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.*;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
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;
|
||||
|
||||
@Mixin(GuiMultiplayer.class)
|
||||
public abstract class MixinGuiMultiplayer extends GuiScreen {
|
||||
private GuiTextField protocolVersion;
|
||||
private GuiButton saveProtocol;
|
||||
|
||||
@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.func_200675_a(new IntegerFormatFilter());
|
||||
this.field_195124_j.add(protocolVersion);
|
||||
saveProtocol = new SaveProtocolButton(6356, width / 2 + 100, 8, 50, 20,
|
||||
I18n.format("gui.save_protocol_version"), protocolVersion);
|
||||
this.field_195124_j.add(saveProtocol);
|
||||
addButton(saveProtocol);
|
||||
}
|
||||
|
||||
@Inject(method = "drawScreen", at = @At("TAIL"))
|
||||
private void onDrawScreen(int p_1, int p_2, float p_3, CallbackInfo ci) {
|
||||
drawCenteredString(fontRenderer, I18n.format("gui.protocol_version"),this.width / 2, 12, 0xFFFFFF);
|
||||
protocolVersion.func_195608_a(p_1, p_2, p_3);
|
||||
}
|
||||
|
||||
//@Inject(method = "keyPressed", at = @At("TAIL"))
|
||||
//private void onKeyPressed(int p_1, int p_2, int p_3, CallbackInfoReturnable<Boolean> cir) {
|
||||
// protocolVersion.keyPressed(p_1, p_2, p_3);
|
||||
//}
|
||||
|
||||
@Inject(method = "updateScreen", at = @At("TAIL"))
|
||||
private void onUpdateScreen(CallbackInfo ci) {
|
||||
protocolVersion.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Inject(method = "getFocused", at = @At("RETURN"), cancellable = true)
|
||||
private void onGetFocused(CallbackInfoReturnable<IGuiEventListener> cir){
|
||||
if (protocolVersion.isFocused()) {
|
||||
cir.setReturnValue(protocolVersion);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,17 @@
|
||||
package com.github.creeper123123321.viarift.platform;
|
||||
|
||||
import com.github.creeper123123321.viarift.provider.VRMovementTransmitter;
|
||||
import com.github.creeper123123321.viarift.provider.VRVersionProvider;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
|
||||
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 VRMovementTransmitter());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,7 +68,7 @@ public class VRViaConfig implements ViaVersionConfig {
|
||||
|
||||
@Override
|
||||
public boolean isAutoTeam() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,45 @@
|
||||
package com.github.creeper123123321.viarift.provider;
|
||||
|
||||
import com.github.creeper123123321.viarift.util.PipelineUtil;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.packets.State;
|
||||
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
|
||||
|
||||
public class VRMovementTransmitter extends MovementTransmitterProvider {
|
||||
@Override
|
||||
public Object getFlyingPacket() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGroundPacket() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayer(UserConnection userConnection) {
|
||||
// Based on https://github.com/Gerrygames/ClientViaVersion/blob/master/src/main/java/de/gerrygames/the5zig/clientviaversion/providers/ClientMovementTransmitterProvider.java
|
||||
if (userConnection.get(ProtocolInfo.class).getState() != State.PLAY) return;
|
||||
|
||||
PacketWrapper packet = new PacketWrapper(0x03, null, userConnection);
|
||||
packet.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround());
|
||||
|
||||
ByteBuf buf = userConnection.getChannel().alloc().buffer();
|
||||
|
||||
try {
|
||||
//Type.VAR_INT.write(buf, PacketWrapper.PASSTHROUGH_ID);
|
||||
packet.writeToBuffer(buf);
|
||||
//PipelineUtil.getContextAfter("encoder", userConnection.getChannel().pipeline()).writeAndFlush(buf);
|
||||
userConnection.getChannel().pipeline().context("encoder").writeAndFlush(buf);
|
||||
//PipelineUtil.getContextBefore("encoder", userConnection.getChannel().pipeline()).writeAndFlush(buf);
|
||||
userConnection.get(MovementTracker.class).incrementIdlePacket();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.github.creeper123123321.viarift.util;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class IntegerFormatFilter implements Predicate<String> {
|
||||
@Override
|
||||
public boolean test(String s) {
|
||||
if (s.isEmpty()) return true;
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
return true;
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,4 +13,8 @@ public class PipelineUtil {
|
||||
}
|
||||
return pipe.context(previous);
|
||||
}
|
||||
|
||||
public static ChannelHandlerContext getContextAfter(String name, ChannelPipeline pipe) {
|
||||
return us.myles.ViaVersion.util.PipelineUtil.getContextBefore(name, pipe);
|
||||
}
|
||||
}
|
||||
|
0
src/main/resources/assets/viarift/.modassetsroot
Normal file
0
src/main/resources/assets/viarift/.modassetsroot
Normal file
4
src/main/resources/assets/viarift/lang/en_us.json
Normal file
4
src/main/resources/assets/viarift/lang/en_us.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"gui.protocol_version": "Protocol version no.: ",
|
||||
"gui.save_protocol_version": "Save"
|
||||
}
|
4
src/main/resources/assets/viarift/lang/pt_br.json
Normal file
4
src/main/resources/assets/viarift/lang/pt_br.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"gui.protocol_version": "Nº de versão do protocolo: ",
|
||||
"gui.save_protocol_version": "Salvar"
|
||||
}
|
@ -8,5 +8,7 @@
|
||||
"mixins": [
|
||||
"MixinNetworkManagerClientChInit"
|
||||
],
|
||||
"client": []
|
||||
"client": [
|
||||
"client.MixinGuiMultiplayer"
|
||||
]
|
||||
}
|
||||
|
6
src/main/resources/pack.mcmeta
Normal file
6
src/main/resources/pack.mcmeta
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"pack_format": 4,
|
||||
"description": "ViaRift"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user