Skip to content

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Dec 23, 2024
1 parent 4a1d71f commit 2f8187c
Show file tree
Hide file tree
Showing 90 changed files with 843 additions and 353 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.util;
package com.viaversion.viafabricplus.base;

import com.viaversion.viafabricplus.features.ClientsideFeatures;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.minecraft.network.PacketByteBuf;
Expand All @@ -30,7 +29,7 @@

public record DataCustomPayload(PacketByteBuf buf) implements CustomPayload {

public static final CustomPayload.Id<DataCustomPayload> ID = new CustomPayload.Id<>(Identifier.of(ClientsideFeatures.PACKET_SYNC_IDENTIFIER));
public static final CustomPayload.Id<DataCustomPayload> ID = new CustomPayload.Id<>(Identifier.of(SyncTasks.PACKET_SYNC_IDENTIFIER));

static {
PayloadTypeRegistry.playS2C().register(DataCustomPayload.ID, CustomPayload.codecOf((value, buf) -> {
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/com/viaversion/viafabricplus/base/SyncTasks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.base;

import net.minecraft.client.MinecraftClient;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.RegistryByteBuf;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

public class SyncTasks {

/**
* Contains all tasks that are waiting for a packet to be received, this system can be used to sync ViaVersion tasks with the correct thread
*/
private static final Map<String, Consumer<RegistryByteBuf>> PENDING_EXECUTION_TASKS = new ConcurrentHashMap<>();

/**
* This identifier is an internal identifier used to identify packets that are sent by ViaFabricPlus
*/
public static final String PACKET_SYNC_IDENTIFIER = UUID.randomUUID() + ":" + UUID.randomUUID();

/**
* Executes a task synchronized with the main thread from networking threads
*
* @param task The task to execute
* @return The uuid of the task
*/
public static String executeSyncTask(final Consumer<RegistryByteBuf> task) {
final String uuid = UUID.randomUUID().toString();
PENDING_EXECUTION_TASKS.put(uuid, task);
return uuid;
}

public static void handleSyncTask(final PacketByteBuf buf) {
final String uuid = buf.readString();

if (PENDING_EXECUTION_TASKS.containsKey(uuid)) {
MinecraftClient.getInstance().execute(() -> { // Execute the task on the main thread
final Consumer<RegistryByteBuf> task = PENDING_EXECUTION_TASKS.remove(uuid);
task.accept(new RegistryByteBuf(buf, MinecraftClient.getInstance().getNetworkHandler().getRegistryManager()));
});
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,61 +25,27 @@
import com.viaversion.viafabricplus.event.ChangeProtocolVersionCallback;
import com.viaversion.viafabricplus.event.PostGameLoadCallback;
import com.viaversion.viafabricplus.features.data.EntityDimensionDiff;
import com.viaversion.viafabricplus.features.data.ResourcePackHeaderDiff;
import com.viaversion.viafabricplus.features.data.recipe.Recipes1_11_2;
import com.viaversion.viafabricplus.features2.networking.resource_pack_header.ResourcePackHeaderDiff;
import com.viaversion.viafabricplus.features2.recipe_emulation.Recipes1_11_2;
import com.viaversion.viafabricplus.features.versioned.EnchantmentAttributesEmulation1_20_6;
import com.viaversion.viafabricplus.features2.cpe_extensions.CPEAdditions;
import com.viaversion.viafabricplus.features.versioned.classic.GridItemSelectionScreen;
import com.viaversion.viafabricplus.features2.ui.classic_creative_menu.GridItemSelectionScreen;
import com.viaversion.viafabricplus.features.versioned.visual.ArmorHudEmulation1_8;
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;
import com.viaversion.viafabricplus.settings.impl.BedrockSettings;
import com.viaversion.viafabricplus.features2.text_rendering.non_existing_characters.UnicodeFontFix1_12_2;
import com.viaversion.viafabricplus.settings.impl.VisualSettings;
import com.viaversion.viafabricplus.util.DataCustomPayload;
import com.viaversion.viafabricplus.base.DataCustomPayload;
import net.minecraft.block.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.registry.Registries;
import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.viabedrock.protocol.data.ProtocolConstants;
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;
import org.jetbrains.annotations.ApiStatus;

import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

/**
* This class contains random fields and methods that are used to fix bugs on the client side
*/
public class ClientsideFeatures {

/**
* Contains all tasks that are waiting for a packet to be received, this system can be used to sync ViaVersion tasks with the correct thread
*/
private static final Map<String, Consumer<RegistryByteBuf>> PENDING_EXECUTION_TASKS = new ConcurrentHashMap<>();

/**
* This identifier is an internal identifier used to identify packets that are sent by ViaFabricPlus
*/
@ApiStatus.Internal
public static final String PACKET_SYNC_IDENTIFIER = UUID.randomUUID() + ":" + UUID.randomUUID();

/**
* This is an incremental index used for tablist entries to implement FIFO behavior <= 1.7
*/
@ApiStatus.Internal
public static int globalTablistIndex = 0;

static {
// Register additional CPE features
CPEAdditions.modifyMappings();
Expand Down Expand Up @@ -148,45 +114,4 @@ public static void init() {
// Calls the static block
}

/**
* Replaces the default port when parsing a server address if the default port should be replaced
*
* @param address The original address of the server
* @param version The protocol version
* @return The server address with the replaced default port
*/
public static String replaceDefaultPort(final String address, final ProtocolVersion version) {
// If the default port for this entry should be replaced, check if the address already contains a port
// We can't just replace vanilla's default port because a bedrock server might be running on the same port
if (BedrockSettings.global().replaceDefaultPort.getValue() && Objects.equals(version, BedrockProtocolVersion.bedrockLatest) && !address.contains(":")) {
return address + ":" + ProtocolConstants.BEDROCK_DEFAULT_PORT;
} else {
return address;
}
}

/**
* Executes a task synchronized with the main thread from networking threads
*
* @param task The task to execute
* @return The uuid of the task
*/
public static String executeSyncTask(final Consumer<RegistryByteBuf> task) {
final String uuid = UUID.randomUUID().toString();
PENDING_EXECUTION_TASKS.put(uuid, task);
return uuid;
}

@ApiStatus.Internal
public static void handleSyncTask(final PacketByteBuf buf) {
final String uuid = buf.readString();

if (PENDING_EXECUTION_TASKS.containsKey(uuid)) {
MinecraftClient.getInstance().execute(() -> { // Execute the task on the main thread
final Consumer<RegistryByteBuf> task = PENDING_EXECUTION_TASKS.remove(uuid);
task.accept(new RegistryByteBuf(buf, MinecraftClient.getInstance().getNetworkHandler().getRegistryManager()));
});
}
}

}
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.classic_world_height;

import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.Via;
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;
package com.viaversion.viafabricplus.features2.interaction;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viafabricplus.ViaFabricPlus;
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;
package com.viaversion.viafabricplus.features2.item.tooltip_changes;

import com.viaversion.viaversion.util.Key;
import net.minecraft.enchantment.Enchantment;
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.networking.resource_pack_header;

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.recipe;
package com.viaversion.viafabricplus.features2.recipe_emulation;

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.recipe;
package com.viaversion.viafabricplus.features2.recipe_emulation;

import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BannerPattern;
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.recipe;
package com.viaversion.viafabricplus.features2.recipe_emulation;

import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack;
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.recipe;
package com.viaversion.viafabricplus.features2.recipe_emulation;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
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.recipe;
package com.viaversion.viafabricplus.features2.recipe_emulation;

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.recipe;
package com.viaversion.viafabricplus.features2.recipe_emulation;

import net.minecraft.block.Block;
import net.minecraft.block.ShulkerBoxBlock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.features.versioned.visual;
package com.viaversion.viafabricplus.features2.text_rendering.non_existing_characters;

import com.viaversion.viafabricplus.injection.mixin.features.text_rendering.MixinFontStorage;
import com.viaversion.viafabricplus.injection.mixin.features.text_rendering.non_existing_characters.MixinFontStorage;
import net.minecraft.client.font.BakedGlyph;
import net.minecraft.client.font.Glyph;
import net.minecraft.client.font.RenderableGlyph;
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.text_rendering.non_existing_characters;

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.versioned.visual;
package com.viaversion.viafabricplus.features2.text_rendering.non_existing_characters;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viafabricplus.event.ChangeProtocolVersionCallback;
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.ui.classic_creative_menu;

import com.viaversion.viafabricplus.features2.item.filter_creative_tabs.ItemRegistryDiff;
import com.viaversion.viafabricplus.screen.VFPScreen;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.ui.v1_7_tab_list_style;

public class LegacyTabList {

/**
* This is an incremental index used for tablist entries to implement FIFO behavior <= 1.7
*/
public static int globalTablistIndex = 0;

}
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.world.disable_sequencing;

import net.minecraft.block.BlockState;
import net.minecraft.client.network.ClientPlayerEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package com.viaversion.viafabricplus.injection.access;

import com.viaversion.viafabricplus.features.versioned.ClientPlayerInteractionManager1_18_2;
import com.viaversion.viafabricplus.features2.interaction.ClientPlayerInteractionManager1_18_2;

public interface IClientPlayerInteractionManager {

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.networking.downloading_terrain_handling;

public interface IDownloadingTerrainScreen {

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.v1_7_tab_list_style;

public interface IPlayerListEntry {

Expand Down
Loading

0 comments on commit 2f8187c

Please sign in to comment.