Skip to content

Commit

Permalink
Features loading
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Dec 23, 2024
1 parent 3a84529 commit 83d4097
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.viaversion.viafabricplus.base.Events;
import com.viaversion.viafabricplus.base.save.SaveManager;
import com.viaversion.viafabricplus.base.settings.SettingsManager;
import com.viaversion.viafabricplus.features.FeaturesLoading;
import com.viaversion.viafabricplus.features.max_chat_length.MaxChatLength;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import com.viaversion.viafabricplus.util.ClassLoaderPriorityUtil;
Expand Down Expand Up @@ -102,6 +103,9 @@ private ViaFabricPlusImpl() {
settingsManager = new SettingsManager();
saveManager = new SaveManager(settingsManager);

// Init features
FeaturesLoading.init();

// Init ViaVersion protocol translator platform
loadingFuture = ProtocolTranslator.init(path);

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

package com.viaversion.viafabricplus.old;
package com.viaversion.viafabricplus.features;

import com.viaversion.viafabricplus.api.LoadingCycleCallback;
import com.viaversion.viafabricplus.base.Events;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viafabricplus.old.data.EntityDimensionDiff;
import com.viaversion.viafabricplus.features.networking.resource_pack_header.ResourcePackHeaderDiff;
import com.viaversion.viafabricplus.features.recipe_emulation.Recipes1_11_2;
import com.viaversion.viafabricplus.old.versioned.EnchantmentAttributesEmulation1_20_6;
import com.viaversion.viafabricplus.base.settings.impl.VisualSettings;
import com.viaversion.viafabricplus.features.block.CollisionShapes;
import com.viaversion.viafabricplus.features.cpe_extensions.CPEAdditions;
import com.viaversion.viafabricplus.features.ui.classic_creative_menu.GridItemSelectionScreen;
import com.viaversion.viafabricplus.features.ui.armor_hud.ArmorHudEmulation1_8;
import com.viaversion.viafabricplus.features.footstep_particle.FootStepParticle1_12_2;
import com.viaversion.viafabricplus.features.networking.resource_pack_header.ResourcePackHeaderDiff;
import com.viaversion.viafabricplus.features.recipe_emulation.Recipes1_11_2;
import com.viaversion.viafabricplus.features.text_rendering.non_existing_characters.UnicodeFontFix1_12_2;
import com.viaversion.viafabricplus.base.settings.impl.VisualSettings;
import com.viaversion.viafabricplus.features.ui.armor_hud.ArmorHudEmulation1_8;
import com.viaversion.viafabricplus.features.ui.classic_creative_menu.GridItemSelectionScreen;
import com.viaversion.viafabricplus.old.data.EntityDimensionDiff;
import com.viaversion.viafabricplus.old.versioned.EnchantmentAttributesEmulation1_20_6;
import com.viaversion.viafabricplus.util.DataCustomPayload;
import net.minecraft.block.*;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.MinecraftClient;
import net.minecraft.registry.Registries;
import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;

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

static {
// Register additional CPE features
CPEAdditions.modifyMappings();

// Check if the pack format mappings are correct
ResourcePackHeaderDiff.checkOutdated();

ResourcePackHeaderDiff.init();
CPEAdditions.init();
DataCustomPayload.init();
UnicodeFontFix1_12_2.init();
FootStepParticle1_12_2.init();

Events.LOADING_CYCLE.register(cycle -> {
if (cycle != LoadingCycleCallback.LoadingCycle.POST_GAME_LOAD) {
return;
if (cycle == LoadingCycleCallback.LoadingCycle.POST_GAME_LOAD) {
EntityDimensionDiff.init();
EnchantmentAttributesEmulation1_20_6.init();
ArmorHudEmulation1_8.init();
}

// Handle clientside enchantment calculations in <= 1.20.6
EnchantmentAttributesEmulation1_20_6.init();

// Handles and updates entity dimension changes in <= 1.17
EntityDimensionDiff.init();

// Ticks the armor hud manually in <= 1.8.x
ArmorHudEmulation1_8.init();
});

// Reloads some clientside stuff when the protocol version changes
Events.CHANGE_PROTOCOL_VERSION.register((oldVersion, newVersion) -> MinecraftClient.getInstance().execute(() -> {
VisualSettings.global().filterNonExistingGlyphs.onValueChanged();
CollisionShapes.reloadBlockShapes();

// Reloads all bounding boxes of the blocks that we changed
for (Block block : Registries.BLOCK) {
if (block instanceof AnvilBlock || block instanceof BedBlock || block instanceof BrewingStandBlock
|| block instanceof CarpetBlock || block instanceof CauldronBlock || block instanceof ChestBlock
|| block instanceof EnderChestBlock || block instanceof EndPortalBlock || block instanceof EndPortalFrameBlock
|| block instanceof FarmlandBlock || block instanceof FenceBlock || block instanceof FenceGateBlock
|| block instanceof HopperBlock || block instanceof LadderBlock || block instanceof LeavesBlock
|| block instanceof LilyPadBlock || block instanceof PaneBlock || block instanceof PistonBlock
|| block instanceof PistonHeadBlock || block instanceof SnowBlock || block instanceof WallBlock
|| block instanceof CropBlock || block instanceof FlowerbedBlock
) {
for (BlockState state : block.getStateManager().getStates()) {
state.initShapeCache();
}
}
}

// Rebuilds the item selection screen grid
if (newVersion.olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
GridItemSelectionScreen.INSTANCE.itemGrid = null;
}

// Reloads the clientside recipes
if (newVersion.olderThanOrEqualTo(ProtocolVersion.v1_11_1)) {
Recipes1_11_2.reset();
}

// Reload sound system when switching between 3D Shareware and normal versions
if (oldVersion.equals(AprilFoolsProtocolVersion.s3d_shareware) || newVersion.equals(AprilFoolsProtocolVersion.s3d_shareware)) {
MinecraftClient.getInstance().getSoundManager().reloadSounds();
}
}));

// Register the footstep particle
FootStepParticle1_12_2.init();

// Register the custom payload packet for sync tasks
DataCustomPayload.init();
}

public static void init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.features.block;

import net.minecraft.block.*;
import net.minecraft.registry.Registries;

public final class CollisionShapes {

public static void reloadBlockShapes() {
for (Block block : Registries.BLOCK) {
if (block instanceof AnvilBlock || block instanceof BedBlock || block instanceof BrewingStandBlock
|| block instanceof CarpetBlock || block instanceof CauldronBlock || block instanceof ChestBlock
|| block instanceof EnderChestBlock || block instanceof EndPortalBlock || block instanceof EndPortalFrameBlock
|| block instanceof FarmlandBlock || block instanceof FenceBlock || block instanceof FenceGateBlock
|| block instanceof HopperBlock || block instanceof LadderBlock || block instanceof LeavesBlock
|| block instanceof LilyPadBlock || block instanceof PaneBlock || block instanceof PistonBlock
|| block instanceof PistonHeadBlock || block instanceof SnowBlock || block instanceof WallBlock
|| block instanceof CropBlock || block instanceof FlowerbedBlock
) {
for (BlockState state : block.getStateManager().getStates()) {
state.initShapeCache();
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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.packet.ClientboundPacketsc0_30cpe;
import org.jetbrains.annotations.ApiStatus;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -45,7 +44,7 @@ public class CPEAdditions {

private static boolean snowing = false;

public static void modifyMappings() {
public static void init() {
allowExtension(ClassicProtocolExtension.ENV_WEATHER_TYPE);
EXT_WEATHER_TYPE = createNewPacket(ClassicProtocolExtension.ENV_WEATHER_TYPE, 31, (user, buf) -> buf.readByte());
}
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.old.versioned.visual;
package com.viaversion.viafabricplus.features.entity.v1_8_boat;

import net.minecraft.client.model.*;
import net.minecraft.client.render.entity.model.EntityModel;
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.old.versioned.visual;
package com.viaversion.viafabricplus.features.entity.v1_8_boat;

import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
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.old.versioned;
package com.viaversion.viafabricplus.features.interaction;

import net.minecraft.util.ActionResult;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import net.minecraft.SaveVersion;
import net.minecraft.SharedConstants;
import net.minecraft.resource.ResourceType;
import org.jetbrains.annotations.ApiStatus;

import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -87,10 +86,11 @@ public class ResourcePackHeaderDiff {
registerVersion(ProtocolVersion.v1_7_2, 1, "1.7.5");
}

public static void checkOutdated() {
public static void init() {
if (!GAME_VERSION_DIFF.containsKey(ProtocolTranslator.NATIVE_VERSION)) {
throw new RuntimeException("The native client version is not registered in the resource pack header diff!");
}
// Also calls the static block
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package com.viaversion.viafabricplus.injection.mixin.features.entity.v1_8_boat;

import com.google.common.collect.ImmutableMap;
import com.viaversion.viafabricplus.old.versioned.visual.BoatModel1_8;
import com.viaversion.viafabricplus.features.entity.v1_8_boat.BoatModel1_8;
import net.minecraft.client.model.TexturedModelData;
import net.minecraft.client.render.entity.model.EntityModelLayer;
import net.minecraft.client.render.entity.model.EntityModels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import com.llamalad7.mixinextras.sugar.Local;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viafabricplus.old.versioned.visual.BoatRenderer1_8;
import com.viaversion.viafabricplus.features.entity.v1_8_boat.BoatRenderer1_8;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ServerboundPackets1_16_2;
import com.viaversion.viaversion.protocols.v1_16_4to1_17.Protocol1_16_4To1_17;
import com.viaversion.viafabricplus.old.versioned.ActionResultException1_12_2;
import com.viaversion.viafabricplus.features.interaction.ActionResultException1_12_2;
import com.viaversion.viafabricplus.features.interaction.ClientPlayerInteractionManager1_18_2;
import com.viaversion.viafabricplus.injection.access.IClientConnection;
import com.viaversion.viafabricplus.injection.access.IClientPlayerInteractionManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.viaversion.viafabricplus.old.versioned.classic.command.ListExtensionsCommand;
import com.viaversion.viafabricplus.old.versioned.classic.command.SetTimeCommand;
import com.viaversion.viafabricplus.protocoltranslator.impl.command.classic.ListExtensionsCommand;
import com.viaversion.viafabricplus.protocoltranslator.impl.command.classic.SetTimeCommand;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.raphimc.vialoader.impl.viaversion.VLCommandHandler;

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.old.versioned.classic.command;
package com.viaversion.viafabricplus.protocoltranslator.impl.command.classic;

import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viafabricplus.injection.access.IExtensionProtocolMetadataStorage;
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.old.versioned.classic.command;
package com.viaversion.viafabricplus.protocoltranslator.impl.command.classic;

import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viafabricplus.protocoltranslator.impl.command.VFPViaSubCommand;
Expand Down

0 comments on commit 83d4097

Please sign in to comment.