Skip to content

Commit

Permalink
More work, start new features package
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Dec 23, 2024
1 parent 61b8228 commit c326444
Show file tree
Hide file tree
Showing 45 changed files with 565 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import com.viaversion.viafabricplus.features.data.ResourcePackHeaderDiff;
import com.viaversion.viafabricplus.features.data.recipe.Recipes1_11_2;
import com.viaversion.viafabricplus.features.versioned.EnchantmentAttributesEmulation1_20_6;
import com.viaversion.viafabricplus.features.versioned.classic.CPEAdditions;
import com.viaversion.viafabricplus.features2.cpe_extensions.CPEAdditions;
import com.viaversion.viafabricplus.features.versioned.classic.GridItemSelectionScreen;
import com.viaversion.viafabricplus.features.versioned.visual.ArmorHudEmulation1_8;
import com.viaversion.viafabricplus.features.versioned.visual.FootStepParticle1_12_2;
import com.viaversion.viafabricplus.features2.footstep_particle.FootStepParticle1_12_2;
import com.viaversion.viafabricplus.features.versioned.visual.UnicodeFontFix1_12_2;
import com.viaversion.viafabricplus.injection.access.IClientConnection;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
Expand Down Expand Up @@ -148,30 +148,6 @@ public static void init() {
// Calls the static block
}

/**
* Calculates the maximum chat length for the selected protocol version in {@link ProtocolTranslator#getTargetVersion()}
*
* @return The maximum chat length
*/
public static int getChatLength() {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
final ClientPlayNetworkHandler handler = MinecraftClient.getInstance().getNetworkHandler();
final ExtensionProtocolMetadataStorage extensionProtocol = ((IClientConnection) handler.getConnection()).viaFabricPlus$getUserConnection().get(ExtensionProtocolMetadataStorage.class);

if (extensionProtocol != null && extensionProtocol.hasServerExtension(ClassicProtocolExtension.LONGER_MESSAGES)) {
return Short.MAX_VALUE * 2;
} else {
return 64 - (MinecraftClient.getInstance().getSession().getUsername().length() + 2);
}
} else if (ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
return 512;
} else if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_9_3)) {
return 100;
} else {
return 256;
}
}

/**
* Replaces the default port when parsing a server address if the default port should be replaced
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package com.viaversion.viafabricplus.features.versioned.classic;

import com.viaversion.viafabricplus.features.data.ItemRegistryDiff;
import com.viaversion.viafabricplus.features2.item.filter_creative_tabs.ItemRegistryDiff;
import com.viaversion.viafabricplus.screen.VFPScreen;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.item.Item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.features.versioned.classic;
package com.viaversion.viafabricplus.features2.cpe_extensions;

import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.features.versioned.visual;
package com.viaversion.viafabricplus.features2.footstep_particle;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.features.data;
package com.viaversion.viafabricplus.features2.item.filter_creative_tabs;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viafabricplus.injection.access.IClientConnection;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <[email protected]>
* - RK_01/RaphiMC
* Copyright (C) 2023-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.features2.item.negative_items;

import com.viaversion.viafabricplus.util.ItemUtil;
import com.viaversion.viaversion.protocols.v1_10to1_11.Protocol1_10To1_11;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;

public class NegativeItemUtil {

private static final String VV_IDENTIFIER = "VV|" + Protocol1_10To1_11.class.getSimpleName(); // ItemRewriter#nbtTagName

/**
* Returns the actual amount of items in the stack, versions older or equal to 1.10 can have negative stack sizes
* which are not represented by {@link ItemStack#getCount()}.
*
* @param stack The stack to get the count from
* @return The actual amount of items in the stack
*/
public static int getCount(final ItemStack stack) {
final NbtCompound tag = ItemUtil.getTagOrNull(stack);
if (tag != null && tag.contains(VV_IDENTIFIER)) {
return tag.getInt(VV_IDENTIFIER);
} else {
return stack.getCount();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.features.versioned;
package com.viaversion.viafabricplus.features2.legacy_chat_signatures;

import com.mojang.authlib.yggdrasil.response.KeyPairResponse;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <[email protected]>
* - RK_01/RaphiMC
* Copyright (C) 2023-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.features2.max_chat_length;

import com.viaversion.viafabricplus.injection.access.IClientConnection;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialegacy.protocol.classic.c0_30cpetoc0_28_30.data.ClassicProtocolExtension;
import net.raphimc.vialegacy.protocol.classic.c0_30cpetoc0_28_30.storage.ExtensionProtocolMetadataStorage;

public class MaxChatLength {

/**
* Calculates the maximum chat length for the selected protocol version in {@link ProtocolTranslator#getTargetVersion()}
*
* @return The maximum chat length
*/
public static int getChatLength() {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
final ClientPlayNetworkHandler handler = MinecraftClient.getInstance().getNetworkHandler();
final ExtensionProtocolMetadataStorage extensionProtocol = ((IClientConnection) handler.getConnection()).viaFabricPlus$getUserConnection().get(ExtensionProtocolMetadataStorage.class);

if (extensionProtocol != null && extensionProtocol.hasServerExtension(ClassicProtocolExtension.LONGER_MESSAGES)) {
return Short.MAX_VALUE * 2;
} else {
return 64 - (MinecraftClient.getInstance().getSession().getUsername().length() + 2);
}
} else if (ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
return 512;
} else if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_9_3)) {
return 100;
} else {
return 256;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.protocoltranslator.util;
package com.viaversion.viafabricplus.features2.mouse_sensitivity;

import it.unimi.dsi.fastutil.floats.FloatIntPair;

public class MathUtil {
public class MouseSensitivity1_13_2 {

public static FloatIntPair get1_13SliderValue(final float value1_14) {
final int oldSliderWidth = 150 - 8;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.injection.access;
package com.viaversion.viafabricplus.injection.access.execute_inputs_sync;

import java.util.Queue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.injection.access;
package com.viaversion.viafabricplus.injection.access.legacy_chat_signatures;

public interface ILegacyKeySignatureStorage {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <[email protected]>
* - RK_01/RaphiMC
* Copyright (C) 2023-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.injection.mixin.base.integration;

import com.llamalad7.mixinextras.sugar.Local;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viafabricplus.injection.access.IClientConnection;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.network.ClientConnection;
import net.raphimc.minecraftauth.step.bedrock.StepMCChain;
import net.raphimc.minecraftauth.step.bedrock.session.StepFullBedrockSession;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.viabedrock.protocol.storage.AuthChainData;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.net.InetSocketAddress;
import java.util.UUID;

@Mixin(targets = "net.minecraft.client.gui.screen.multiplayer.ConnectScreen$1")
public abstract class MixinConnectScreen_1 {

@Final
@Shadow
ServerAddress field_33737;

@Inject(method = "run", at = @At(value = "INVOKE", target = "Lio/netty/channel/ChannelFuture;syncUninterruptibly()Lio/netty/channel/ChannelFuture;", remap = false, shift = At.Shift.AFTER))
private void setupBedrockAccount(CallbackInfo ci, @Local ClientConnection clientConnection) {
final UserConnection userConnection = ((IClientConnection) clientConnection).viaFabricPlus$getUserConnection();

if (ProtocolTranslator.getTargetVersion() == BedrockProtocolVersion.bedrockLatest) {
final StepFullBedrockSession.FullBedrockSession bedrockSession = ViaFabricPlus.global().getSaveManager().getAccountsSave().refreshAndGetBedrockAccount();
if (bedrockSession != null) {
final StepMCChain.MCChain mcChain = bedrockSession.getMcChain();
final UUID deviceId = mcChain.getXblXsts().getInitialXblSession().getXblDeviceToken().getId();
final String playFabId = bedrockSession.getPlayFabToken().getPlayFabId();

userConnection.put(new AuthChainData(mcChain.getMojangJwt(), mcChain.getIdentityJwt(), mcChain.getPublicKey(), mcChain.getPrivateKey(), deviceId, playFabId));
} else {
ViaFabricPlus.global().getLogger().warn("Could not get Bedrock account. Joining online mode servers will not work!");
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.injection.mixin.features.bedrock;
package com.viaversion.viafabricplus.injection.mixin.features.bedrock.chat_suggestions;

import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.client.network.ClientCommandSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package com.viaversion.viafabricplus.injection.mixin.features.cpe_extensions;

import com.viaversion.viafabricplus.features.versioned.classic.CPEAdditions;
import com.viaversion.viafabricplus.features2.cpe_extensions.CPEAdditions;
import net.raphimc.vialegacy.protocol.classic.c0_30cpetoc0_28_30.data.ClassicProtocolExtension;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package com.viaversion.viafabricplus.injection.mixin.features.cpe_extensions;

import com.viaversion.viafabricplus.features.versioned.classic.CPEAdditions;
import com.viaversion.viafabricplus.features2.cpe_extensions.CPEAdditions;
import net.raphimc.vialegacy.protocol.classic.c0_30cpetoc0_28_30.packet.ClientboundPacketsc0_30cpe;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.Protocol1_19_3To1_19_4;
import com.viaversion.viaversion.protocols.v1_19_3to1_19_4.packet.ClientboundPackets1_19_4;
import com.viaversion.viafabricplus.features.versioned.classic.CPEAdditions;
import com.viaversion.viafabricplus.features2.cpe_extensions.CPEAdditions;
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.packet.ClientboundPacketsc0_28;
import net.raphimc.vialegacy.protocol.classic.c0_28_30toa1_0_15.packet.ServerboundPacketsc0_28;
import net.raphimc.vialegacy.protocol.classic.c0_30cpetoc0_28_30.Protocolc0_30cpeToc0_28_30;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package com.viaversion.viafabricplus.injection.mixin.features.cpe_extensions;

import com.viaversion.viafabricplus.features.versioned.classic.CPEAdditions;
import com.viaversion.viafabricplus.features2.cpe_extensions.CPEAdditions;
import net.minecraft.client.render.WeatherRendering;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package com.viaversion.viafabricplus.injection.mixin.features.execute_inputs_sync;

import com.viaversion.viafabricplus.injection.access.IMouseKeyboard;
import com.viaversion.viafabricplus.injection.access.execute_inputs_sync.IMouseKeyboard;
import com.viaversion.viafabricplus.settings.impl.DebugSettings;
import net.minecraft.client.Keyboard;
import net.minecraft.client.MinecraftClient;
Expand Down
Loading

0 comments on commit c326444

Please sign in to comment.