mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-29 12:55:14 +01:00
19w11b, GUI changes, use Fabric for I18N
This commit is contained in:
parent
f1c5c32a0e
commit
7b4248d2ae
@ -10,7 +10,7 @@ plugins {
|
|||||||
group 'com.github.creeper123123321.viafabric'
|
group 'com.github.creeper123123321.viafabric'
|
||||||
version '0.1.0-SNAPSHOT+' + gitVersion()
|
version '0.1.0-SNAPSHOT+' + gitVersion()
|
||||||
archivesBaseName = 'ViaFabric'
|
archivesBaseName = 'ViaFabric'
|
||||||
description = 'Clientside and serverside ViaVersion for Fabric'
|
description = 'Client-side and server-side ViaVersion for Fabric'
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
targetCompatibility = 1.8
|
targetCompatibility = 1.8
|
||||||
@ -37,11 +37,11 @@ dependencies {
|
|||||||
compile("de.gerrygames:viarewind-core:1.4.0") { transitive = false }
|
compile("de.gerrygames:viarewind-core:1.4.0") { transitive = false }
|
||||||
compile("nl.matsv:viabackwards-core:2.4.0-SNAPSHOT") { transitive = false }
|
compile("nl.matsv:viabackwards-core:2.4.0-SNAPSHOT") { transitive = false }
|
||||||
|
|
||||||
minecraft "com.mojang:minecraft:19w09a"
|
minecraft "com.mojang:minecraft:19w11b"
|
||||||
mappings "net.fabricmc:yarn:19w09a.2"
|
mappings "net.fabricmc:yarn:19w11b.2"
|
||||||
modCompile "net.fabricmc:fabric-loader:0.3.7.109"
|
modCompile "net.fabricmc:fabric-loader:0.3.7.109"
|
||||||
|
|
||||||
modCompile "net.fabricmc:fabric:0.2.3.108"
|
modCompile "net.fabricmc:fabric:0.2.3.110"
|
||||||
}
|
}
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.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;
|
|
||||||
|
|
||||||
public SaveProtocolButton(int x, int y, int width, int height, String text, TextFieldWidget tf) {
|
|
||||||
super(x, y, width, height, text);
|
|
||||||
textField = tf;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 {
|
|
||||||
newVersion = Integer.parseInt(textField.getText());
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
ProtocolVersion closest = ProtocolVersion.getClosest(textField.getText());
|
|
||||||
if (closest != null) newVersion = closest.getId();
|
|
||||||
}
|
|
||||||
((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion = newVersion;
|
|
||||||
textField.setText(ProtocolVersion.isRegistered(newVersion)
|
|
||||||
? ProtocolVersion.getProtocol(newVersion).getName()
|
|
||||||
: Integer.toString(newVersion));
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,10 +24,8 @@
|
|||||||
|
|
||||||
package com.github.creeper123123321.viafabric.mixin.client;
|
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.providers.VRVersionProvider;
|
||||||
import com.github.creeper123123321.viafabric.util.VersionFormatFilter;
|
import com.github.creeper123123321.viafabric.util.VersionFormatFilter;
|
||||||
import net.minecraft.client.gui.InputListener;
|
|
||||||
import net.minecraft.client.gui.Screen;
|
import net.minecraft.client.gui.Screen;
|
||||||
import net.minecraft.client.gui.menu.MultiplayerScreen;
|
import net.minecraft.client.gui.menu.MultiplayerScreen;
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
@ -36,32 +34,51 @@ import org.spongepowered.asm.mixin.Mixin;
|
|||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
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.Via;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
||||||
|
|
||||||
@Mixin(MultiplayerScreen.class)
|
@Mixin(MultiplayerScreen.class)
|
||||||
public abstract class MixinMultiplayerGui extends Screen {
|
public abstract class MixinMultiplayerGui extends Screen {
|
||||||
private TextFieldWidget protocolVersion;
|
private TextFieldWidget protocolVersion;
|
||||||
|
private boolean validProtocol = true;
|
||||||
|
private boolean supportedProtocol;
|
||||||
|
|
||||||
@Inject(method = "onInitialized", at = @At("TAIL"))
|
@Inject(method = "method_2540", at = @At("TAIL"))
|
||||||
private void onOnInitialized(CallbackInfo ci) {
|
private void onInitWidgets(CallbackInfo ci) {
|
||||||
protocolVersion = new TextFieldWidget(fontRenderer, this.screenWidth / 2 + 55, 8, 45, 20);
|
protocolVersion = new TextFieldWidget(fontRenderer, this.screenWidth / 2 + 70, 8, 45, 20);
|
||||||
int clientSideVersion = ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion;
|
int clientSideVersion = ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion;
|
||||||
|
supportedProtocol = isSupported(clientSideVersion);
|
||||||
protocolVersion.setText(ProtocolVersion.isRegistered(clientSideVersion)
|
protocolVersion.setText(ProtocolVersion.isRegistered(clientSideVersion)
|
||||||
? ProtocolVersion.getProtocol(clientSideVersion).getName()
|
? ProtocolVersion.getProtocol(clientSideVersion).getName()
|
||||||
: Integer.toString(clientSideVersion));
|
: Integer.toString(clientSideVersion));
|
||||||
protocolVersion.method_1890(new VersionFormatFilter());
|
protocolVersion.method_1890(new VersionFormatFilter());
|
||||||
|
protocolVersion.setChangedListener((text) -> {
|
||||||
|
int newVersion = ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion;
|
||||||
|
validProtocol = true;
|
||||||
|
try {
|
||||||
|
newVersion = Integer.parseInt(text);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
ProtocolVersion closest = ProtocolVersion.getClosest(text);
|
||||||
|
if (closest != null) newVersion = closest.getId();
|
||||||
|
else validProtocol = false;
|
||||||
|
}
|
||||||
|
supportedProtocol = isSupported(newVersion);
|
||||||
|
((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion = newVersion;
|
||||||
|
});
|
||||||
this.listeners.add(protocolVersion);
|
this.listeners.add(protocolVersion);
|
||||||
addButton(new SaveProtocolButton(screenWidth / 2 + 100, 8, 50, 20,
|
|
||||||
I18n.translate("selectWorld.edit.save"), protocolVersion));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "draw", at = @At("TAIL"))
|
@Inject(method = "draw", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Screen;draw(IIF)V"))
|
||||||
private void onDraw(int p_1, int p_2, float p_3, CallbackInfo ci) {
|
private void onDraw(int int_1, int int_2, float float_1, CallbackInfo ci) {
|
||||||
drawStringCentered(fontRenderer, "Protocol Version:", this.screenWidth / 2, 12, 0xFFFFFF);
|
drawStringCentered(fontRenderer, I18n.translate("viafabric.gui.protocol_version"), this.screenWidth / 2, 11, 0xFFFFFF);
|
||||||
protocolVersion.draw(p_1, p_2, p_3);
|
if (!validProtocol) {
|
||||||
|
drawString(fontRenderer, I18n.translate("viafabric.gui.invalid_protocol"), screenWidth / 2 + 120, 15, 0xff0000);
|
||||||
|
} else if (!supportedProtocol) {
|
||||||
|
drawString(fontRenderer, I18n.translate("viafabric.gui.unsupported_protocol"), screenWidth / 2 + 120, 15, 0xff0000);
|
||||||
|
}
|
||||||
|
protocolVersion.draw(int_1, int_2, float_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "update", at = @At("TAIL"))
|
@Inject(method = "update", at = @At("TAIL"))
|
||||||
@ -69,10 +86,8 @@ public abstract class MixinMultiplayerGui extends Screen {
|
|||||||
protocolVersion.tick();
|
protocolVersion.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "getFocused", at = @At("HEAD"), cancellable = true, remap = false)
|
private boolean isSupported(int protocol) {
|
||||||
private void onGetFocused(CallbackInfoReturnable<InputListener> cir) {
|
return ProtocolRegistry.getProtocolPath(ProtocolRegistry.SERVER_PROTOCOL, protocol) != null
|
||||||
if (protocolVersion.isFocused()) {
|
|| ProtocolRegistry.SERVER_PROTOCOL == protocol;
|
||||||
cir.setReturnValue(protocolVersion);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ public class VRPlatform implements ViaPlatform {
|
|||||||
@Override
|
@Override
|
||||||
public ViaCommandSender[] getOnlinePlayers() {
|
public ViaCommandSender[] getOnlinePlayers() {
|
||||||
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
|
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
|
||||||
if (server != null && server.isMainThread()) {
|
if (server != null && server.method_18854()) {
|
||||||
// Not thread safe
|
// Not thread safe
|
||||||
return server.getPlayerManager().getPlayerList().stream()
|
return server.getPlayerManager().getPlayerList().stream()
|
||||||
.map(Entity::getCommandSource)
|
.map(Entity::getCommandSource)
|
||||||
@ -213,7 +213,7 @@ public class VRPlatform implements ViaPlatform {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
|
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
|
||||||
if (server != null && server.isMainThread()) {
|
if (server != null && server.method_18854()) {
|
||||||
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(TextComponent.Serializer.fromJsonString(ChatRewriter.legacyTextToJson(s)));
|
player.networkHandler.disconnect(TextComponent.Serializer.fromJsonString(ChatRewriter.legacyTextToJson(s)));
|
||||||
|
5
src/main/resources/assets/viafabric/lang/en_us.json
Normal file
5
src/main/resources/assets/viafabric/lang/en_us.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"viafabric.gui.protocol_version": "Protocol Version:",
|
||||||
|
"viafabric.gui.invalid_protocol": "INVALID",
|
||||||
|
"viafabric.gui.unsupported_protocol": "UNSUPPORTED"
|
||||||
|
}
|
5
src/main/resources/assets/viafabric/lang/pt_br.json
Normal file
5
src/main/resources/assets/viafabric/lang/pt_br.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"viafabric.gui.protocol_version": "Versão do protocolo:",
|
||||||
|
"viafabric.gui.invalid_protocol": "INVÁLIDO",
|
||||||
|
"viafabric.gui.unsupported_protocol": "SEM SUPORTE"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user