mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-25 12:15:14 +01:00
19w11b, GUI changes, use Fabric for I18N
This commit is contained in:
parent
f1c5c32a0e
commit
7b4248d2ae
10
build.gradle
10
build.gradle
@ -10,7 +10,7 @@ plugins {
|
||||
group 'com.github.creeper123123321.viafabric'
|
||||
version '0.1.0-SNAPSHOT+' + gitVersion()
|
||||
archivesBaseName = 'ViaFabric'
|
||||
description = 'Clientside and serverside ViaVersion for Fabric'
|
||||
description = 'Client-side and server-side ViaVersion for Fabric'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
targetCompatibility = 1.8
|
||||
@ -36,12 +36,12 @@ dependencies {
|
||||
compile("us.myles:viaversion:2.0.0-19w09a") { transitive = false }
|
||||
compile("de.gerrygames:viarewind-core:1.4.0") { transitive = false }
|
||||
compile("nl.matsv:viabackwards-core:2.4.0-SNAPSHOT") { transitive = false }
|
||||
|
||||
minecraft "com.mojang:minecraft:19w09a"
|
||||
mappings "net.fabricmc:yarn:19w09a.2"
|
||||
|
||||
minecraft "com.mojang:minecraft:19w11b"
|
||||
mappings "net.fabricmc:yarn:19w11b.2"
|
||||
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 {
|
||||
|
@ -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;
|
||||
|
||||
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.InputListener;
|
||||
import net.minecraft.client.gui.Screen;
|
||||
import net.minecraft.client.gui.menu.MultiplayerScreen;
|
||||
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.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 {
|
||||
private TextFieldWidget protocolVersion;
|
||||
private boolean validProtocol = true;
|
||||
private boolean supportedProtocol;
|
||||
|
||||
@Inject(method = "onInitialized", at = @At("TAIL"))
|
||||
private void onOnInitialized(CallbackInfo ci) {
|
||||
protocolVersion = new TextFieldWidget(fontRenderer, this.screenWidth / 2 + 55, 8, 45, 20);
|
||||
@Inject(method = "method_2540", at = @At("TAIL"))
|
||||
private void onInitWidgets(CallbackInfo ci) {
|
||||
protocolVersion = new TextFieldWidget(fontRenderer, this.screenWidth / 2 + 70, 8, 45, 20);
|
||||
int clientSideVersion = ((VRVersionProvider) Via.getManager().getProviders().get(VersionProvider.class)).clientSideModeVersion;
|
||||
supportedProtocol = isSupported(clientSideVersion);
|
||||
protocolVersion.setText(ProtocolVersion.isRegistered(clientSideVersion)
|
||||
? ProtocolVersion.getProtocol(clientSideVersion).getName()
|
||||
: Integer.toString(clientSideVersion));
|
||||
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);
|
||||
addButton(new SaveProtocolButton(screenWidth / 2 + 100, 8, 50, 20,
|
||||
I18n.translate("selectWorld.edit.save"), protocolVersion));
|
||||
}
|
||||
|
||||
@Inject(method = "draw", at = @At("TAIL"))
|
||||
private void onDraw(int p_1, int p_2, float p_3, CallbackInfo ci) {
|
||||
drawStringCentered(fontRenderer, "Protocol Version:", this.screenWidth / 2, 12, 0xFFFFFF);
|
||||
protocolVersion.draw(p_1, p_2, p_3);
|
||||
@Inject(method = "draw", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Screen;draw(IIF)V"))
|
||||
private void onDraw(int int_1, int int_2, float float_1, CallbackInfo ci) {
|
||||
drawStringCentered(fontRenderer, I18n.translate("viafabric.gui.protocol_version"), this.screenWidth / 2, 11, 0xFFFFFF);
|
||||
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"))
|
||||
@ -69,10 +86,8 @@ public abstract class MixinMultiplayerGui extends Screen {
|
||||
protocolVersion.tick();
|
||||
}
|
||||
|
||||
@Inject(method = "getFocused", at = @At("HEAD"), cancellable = true, remap = false)
|
||||
private void onGetFocused(CallbackInfoReturnable<InputListener> cir) {
|
||||
if (protocolVersion.isFocused()) {
|
||||
cir.setReturnValue(protocolVersion);
|
||||
}
|
||||
private boolean isSupported(int protocol) {
|
||||
return ProtocolRegistry.getProtocolPath(ProtocolRegistry.SERVER_PROTOCOL, protocol) != null
|
||||
|| ProtocolRegistry.SERVER_PROTOCOL == protocol;
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ public class VRPlatform implements ViaPlatform {
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
|
||||
if (server != null && server.isMainThread()) {
|
||||
if (server != null && server.method_18854()) {
|
||||
// Not thread safe
|
||||
return server.getPlayerManager().getPlayerList().stream()
|
||||
.map(Entity::getCommandSource)
|
||||
@ -213,7 +213,7 @@ public class VRPlatform implements ViaPlatform {
|
||||
}
|
||||
} else {
|
||||
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
|
||||
if (server != null && server.isMainThread()) {
|
||||
if (server != null && server.method_18854()) {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
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