Skip to content

Commit

Permalink
Renamed ProtocolHack to ProtocolTranslator
Browse files Browse the repository at this point in the history
I decided to use ProtocolTranslator as new name since it better describes what this part of the program is doing
  • Loading branch information
FlorianMichael committed Feb 15, 2024
1 parent da73e8b commit 5f0ac0c
Show file tree
Hide file tree
Showing 170 changed files with 565 additions and 566 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import de.florianmichael.viafabricplus.event.PostGameLoadCallback;
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;

This comment has been minimized.

Copy link
@Kichura

Kichura Feb 15, 2024

Member

Hacks? What hacks?
This is clearly a translator, chief.

import de.florianmichael.viafabricplus.save.SaveManager;
import de.florianmichael.viafabricplus.settings.SettingsManager;
import de.florianmichael.viafabricplus.util.ClassLoaderPriorityUtil;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void bootstrap() {
saveManager = new SaveManager(settingsManager);

ClientsideFixes.init(); // Init clientside related fixes
loadingFuture = ProtocolHack.init(directory); // Init ViaVersion protocol translator platform
loadingFuture = ProtocolTranslator.init(directory); // Init ViaVersion protocol translator platform

PostGameLoadCallback.EVENT.register(() -> loadingFuture.join()); // Block game loading until ViaVersion has loaded
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import de.florianmichael.viafabricplus.fixes.versioned.visual.FootStepParticle1_12_2;
import de.florianmichael.viafabricplus.injection.ViaFabricPlusMixinPlugin;
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.block.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.FontStorage;
Expand Down Expand Up @@ -120,12 +120,12 @@ public static void init() {
}

/**
* Calculates the maximum chat length for the selected protocol version in {@link ProtocolHack#getTargetVersion()}
* Calculates the maximum chat length for the selected protocol version in {@link ProtocolTranslator#getTargetVersion()}
*
* @return The maximum chat length
*/
public static int getChatLength() {
if (ProtocolHack.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
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);

Expand All @@ -134,9 +134,9 @@ public static int getChatLength() {
} else {
return 64 - (MinecraftClient.getInstance().getSession().getUsername().length() + 2);
}
} else if (ProtocolHack.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
} else if (ProtocolTranslator.getTargetVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
return 512;
} else if (ProtocolHack.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_9_3)) {
} else if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_9_3)) {
return 100;
} else {
return 256;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.item.Item;
Expand Down Expand Up @@ -1365,7 +1365,7 @@ public class ItemRegistryDiff {
* @return true if the item exists in the current version, false otherwise, this will also check for CPE items (CustomBlocks V1 extension)
*/
public static boolean keepItem(final Item item) {
if (ProtocolHack.getTargetVersion().equals(c0_30cpe)) {
if (ProtocolTranslator.getTargetVersion().equals(c0_30cpe)) {
final ClientPlayNetworkHandler handler = MinecraftClient.getInstance().getNetworkHandler();
if (handler == null) {
// Don't drop any items if the connection is not established yet
Expand All @@ -1380,7 +1380,7 @@ public static boolean keepItem(final Item item) {
}
}

return contains(item, ProtocolHack.getTargetVersion());
return contains(item, ProtocolTranslator.getTargetVersion());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package de.florianmichael.viafabricplus.fixes.data;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -1109,7 +1109,7 @@ public enum Material1_19_4 {
* @return The material of the block for game version 1.19.4
*/
public static Material1_19_4 getMaterial(final Block block) {
if (block instanceof ShulkerBoxBlock && ProtocolHack.getTargetVersion().olderThan(ProtocolVersion.v1_14)) {
if (block instanceof ShulkerBoxBlock && ProtocolTranslator.getTargetVersion().olderThan(ProtocolVersion.v1_14)) {
return STONE;
} else {
return MATERIALS.get(block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package de.florianmichael.viafabricplus.fixes.data;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntConsumer;
Expand Down Expand Up @@ -975,7 +975,7 @@ public class RenderableGlyphDiff {
* @return true if the given code point is renderable in the current version of the game
*/
public static boolean isGlyphRenderable(final int codePoint) {
final ProtocolVersion targetVersion = ProtocolHack.getTargetVersion();
final ProtocolVersion targetVersion = ProtocolTranslator.getTargetVersion();

if (targetVersion.newerThanOrEqualTo(v1_20)) { // 1.20 switched to using Unihex as a main font
return !RENDERABLE_GLYPH_DIFF.containsKey(codePoint) || targetVersion.newerThanOrEqualTo(RENDERABLE_GLYPH_DIFF.get(codePoint));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package de.florianmichael.viafabricplus.fixes.data.recipe;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.block.entity.BannerBlockEntity;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.BannerItem;
Expand Down Expand Up @@ -76,7 +76,7 @@ public ItemStack craft(RecipeInputInventory inv, DynamicRegistryManager registry

BannerPattern_1_13_2 pattern = getBannerPattern(inv);
if (pattern != null) {
DyeColor color = ProtocolHack.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_2) ? DyeColor.BLACK : DyeColor.WHITE;
DyeColor color = ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_2) ? DyeColor.BLACK : DyeColor.WHITE;
for (int i = 0; i < inv.size(); i++) {
Item item = inv.getStack(i).getItem();
if (item instanceof DyeItem dyeItem) {
Expand Down Expand Up @@ -138,7 +138,7 @@ private static BannerPattern_1_13_2 getBannerPattern(RecipeInputInventory inv) {
}
}
}
if (!foundBaseItem || (!foundDye && ProtocolHack.getTargetVersion().newerThan(ProtocolVersion.v1_10))) matches = false;
if (!foundBaseItem || (!foundDye && ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_10))) matches = false;
} else if (inv.size() == pattern.getRecipePattern().length * pattern.getRecipePattern()[0].length()) {
DyeColor patternColor = null;
for (int i = 0; i < inv.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
Expand All @@ -41,7 +41,7 @@ public void trackPlayerAction(final PlayerActionC2SPacket.Action action, final B
final ClientPlayerEntity player = MinecraftClient.getInstance().player;

final Vec2f rotation;
if (ProtocolHack.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_16_1)) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_16_1)) {
rotation = null;
} else {
rotation = new Vec2f(player.getYaw(), player.getPitch());
Expand All @@ -58,9 +58,9 @@ public void handleBlockBreakAck(final BlockPos blockPos, final BlockState expect
final var oldPlayerState = unAckedActions.remove(Pair.of(blockPos, action));
final var actualState = world.getBlockState(blockPos);

if ((oldPlayerState == null || !allGood || action != PlayerActionC2SPacket.Action.START_DESTROY_BLOCK && actualState != expectedState) && (actualState != expectedState || ProtocolHack.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_15_2))) {
if ((oldPlayerState == null || !allGood || action != PlayerActionC2SPacket.Action.START_DESTROY_BLOCK && actualState != expectedState) && (actualState != expectedState || ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_15_2))) {
world.setBlockState(blockPos, expectedState, Block.NOTIFY_ALL | Block.FORCE_STATE);
if (oldPlayerState != null && (ProtocolHack.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_16_1) || (world == player.getWorld() && player.collidesWithStateAtPos(blockPos, expectedState)))) {
if (oldPlayerState != null && (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_16_1) || (world == player.getWorld() && player.collidesWithStateAtPos(blockPos, expectedState)))) {
final Vec3d oldPlayerPosition = oldPlayerState.getKey();
if (oldPlayerState.getValue() != null) {
player.updatePositionAndAngles(oldPlayerPosition.x, oldPlayerPosition.y, oldPlayerPosition.z, oldPlayerState.getValue().x, oldPlayerState.getValue().y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import com.viaversion.viaversion.api.command.ViaCommandSender;
import de.florianmichael.viafabricplus.injection.access.IExtensionProtocolMetadataStorage;
import de.florianmichael.viafabricplus.protocolhack.impl.command.VFPViaSubCommand;
import de.florianmichael.viafabricplus.protocoltranslator.impl.command.VFPViaSubCommand;
import net.minecraft.util.Formatting;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage.ExtensionProtocolMetadataStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package de.florianmichael.viafabricplus.fixes.versioned.classic.command;

import com.viaversion.viaversion.api.command.ViaCommandSender;
import de.florianmichael.viafabricplus.protocolhack.impl.command.VFPViaSubCommand;
import de.florianmichael.viafabricplus.protocoltranslator.impl.command.VFPViaSubCommand;
import net.minecraft.util.Formatting;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_17_1_0_17_4toa1_0_16_2.storage.TimeLockStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import de.florianmichael.viafabricplus.settings.impl.VisualSettings;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
Expand All @@ -48,7 +48,7 @@ public static void init() {
}

if (MinecraftClient.getInstance().player != null) {
final UserConnection userConnection = ProtocolHack.getPlayNetworkUserConnection();
final UserConnection userConnection = ProtocolTranslator.getPlayNetworkUserConnection();
if (userConnection != null) {
try {
sendArmorUpdate(userConnection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package de.florianmichael.viafabricplus.fixes.versioned.visual;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityPose;
Expand Down Expand Up @@ -55,7 +55,7 @@ public static Vector3f getMountedHeightOffset(final Entity entity, final Entity
if (entity instanceof BoatEntity boatEntity) {
if (!boatEntity.hasPassenger(passenger)) return new Vector3f();

if (ProtocolHack.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) {
yOffset = -0.3F;
final float xOffset = MathHelper.cos(boatEntity.getYaw() * MathHelper.PI / 180F);
final float zOffset = MathHelper.sin(boatEntity.getYaw() * MathHelper.PI / 180F);
Expand Down Expand Up @@ -149,7 +149,7 @@ public static Vector3f getMountedHeightOffset(final Entity entity, final Entity
*/
public static double getHeightOffset(final Entity entity) {
if (entity instanceof AllayEntity || entity instanceof VexEntity) {
if (ProtocolHack.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_19_1)) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_19_1)) {
return 0D;
} else {
return 0.4D;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package de.florianmichael.viafabricplus.fixes.versioned.visual;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.particle.v1.FabricParticleTypes;
import net.minecraft.client.particle.*;
Expand Down Expand Up @@ -96,7 +96,7 @@ public Factory(SpriteProvider spriteProvider) {

@Override
public Particle createParticle(DefaultParticleType parameters, ClientWorld world, double x, double y, double z, double velocityX, double velocityY, double velocityZ) {
if (ProtocolHack.getTargetVersion().newerThan(ProtocolVersion.v1_12_2)) {
if (ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_12_2)) {
throw new UnsupportedOperationException("FootStepParticle is not supported on versions newer than 1.12.2");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
import de.florianmichael.viafabricplus.injection.access.IPerformanceLog;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocolhack.netty.ViaFabricPlusVLLegacyPipeline;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import de.florianmichael.viafabricplus.protocoltranslator.netty.ViaFabricPlusVLLegacyPipeline;
import io.netty.bootstrap.AbstractBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
Expand Down Expand Up @@ -138,10 +138,10 @@ private static boolean dontSetPerformanceLog(ClientConnection instance, Performa
private static void setTargetVersion(InetSocketAddress address, boolean useEpoll, ClientConnection connection, CallbackInfoReturnable<ChannelFuture> cir) {
ProtocolVersion targetVersion = ((IClientConnection) connection).viaFabricPlus$getTargetVersion();
if (targetVersion == null) { // No server specific override
targetVersion = ProtocolHack.getTargetVersion();
targetVersion = ProtocolTranslator.getTargetVersion();
}
if (targetVersion == ProtocolHack.AUTO_DETECT_PROTOCOL) { // Auto-detect enabled (when pinging always use native version). Auto-detect is resolved in ConnectScreen mixin
targetVersion = ProtocolHack.NATIVE_VERSION;
if (targetVersion == ProtocolTranslator.AUTO_DETECT_PROTOCOL) { // Auto-detect enabled (when pinging always use native version). Auto-detect is resolved in ConnectScreen mixin
targetVersion = ProtocolTranslator.NATIVE_VERSION;
}

((IClientConnection) connection).viaFabricPlus$setTargetVersion(targetVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package de.florianmichael.viafabricplus.injection.mixin.base.connect;

import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
import io.netty.channel.Channel;
import net.minecraft.network.ClientConnection;
import org.spongepowered.asm.mixin.Final;
Expand All @@ -38,7 +38,7 @@ public abstract class MixinClientConnection_1 {

@Inject(method = "initChannel", at = @At("RETURN"))
private void injectViaIntoPipeline(Channel channel, CallbackInfo ci) {
ProtocolHack.injectViaPipeline(this.field_11663, channel);
ProtocolTranslator.injectViaPipeline(this.field_11663, channel);
}

}
Loading

0 comments on commit 5f0ac0c

Please sign in to comment.