Skip to content

Commit

Permalink
Add visuals fabric mod, add loading cycle entrypoint for addons
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Dec 24, 2024
1 parent 50a8c1e commit 10bcd40
Show file tree
Hide file tree
Showing 72 changed files with 745 additions and 278 deletions.
2 changes: 2 additions & 0 deletions api-legacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ plugins {

dependencies {
compileOnly project(":viafabricplus-api")

// They don't matter and are only used to compile against
compileOnly "com.viaversion:viaversion-common:5.2.1-SNAPSHOT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 de.florianmichael.viafabricplus.fixes.data;

import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.item.Item;

/**
* Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point.
*/
@Deprecated
public class ItemRegistryDiff {

@Deprecated
public static boolean keepItem(final Item item) {
return ViaFabricPlus.getImpl().itemExistsInConnection(item);
}

@Deprecated
public static boolean contains(final Item item, final ProtocolVersion version) {
return ViaFabricPlus.getImpl().itemExists(item, version);
}

}
1 change: 1 addition & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
}

dependencies {
// They don't matter and are only used to compile against
compileOnly "com.viaversion:viaversion-common:5.2.1-SNAPSHOT"
compileOnly ("net.raphimc:ViaLoader:3.0.4") {
exclude group: "com.google.guava", module: "guava"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ default int apiVersion() {
void registerOnChangeProtocolVersionCallback(final ChangeProtocolVersionCallback callback);

/**
* Register a callback for the loading cycle which covers most of the loading process of the mod.
* Register a callback for the loading cycle which covers most of the loading process of the mod. Intended to be used
* inside {@link com.viaversion.viafabricplus.api.entrypoint.ViaFabricPlusLoadEntrypoint} implementations.
*
* @param callback the callback
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.api.entrypoint;

import com.viaversion.viafabricplus.api.ViaFabricPlusBase;

/**
* Entrypoint called before the ViaFabricPlus loading cycle starts. To be used by addons to register their own callbacks.
* <p>
* See {@link com.viaversion.viafabricplus.api.events.LoadingCycleCallback} for more information.
*/
@FunctionalInterface
public interface ViaFabricPlusLoadEntrypoint {

void onPlatformLoad(final ViaFabricPlusBase platform);

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ public interface LoadingCycleCallback {

enum LoadingCycle {

/**
* Earliest stage before ViaFabricPlus loads anything.
*/
INITIAL_LOAD,

/**
* Before the settings are loaded.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package com.viaversion.viafabricplus.screen;

import com.viaversion.viafabricplus.ViaFabricPlusImpl;
import com.viaversion.viafabricplus.ViaFabricPlus;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ConfirmLinkScreen;
Expand Down Expand Up @@ -233,7 +233,7 @@ public static void playClickSound() {
* @param next The screen which should be opened after the error screen is closed
*/
public static void showErrorScreen(final Text title, final Throwable throwable, final Screen next) {
ViaFabricPlusImpl.INSTANCE.logger().error("Something went wrong!", throwable);
ViaFabricPlus.getImpl().logger().error("Something went wrong!", throwable);

final MinecraftClient client = MinecraftClient.getInstance();
client.execute(() -> client.setScreen(new NoticeScreen(() -> client.setScreen(next), title, Text.translatable("base.viafabricplus.something_went_wrong").append("\n" + throwable.getMessage()), Text.translatable("base.viafabricplus.cancel"), false)));
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {

// Manually include to ignore dependencies
include implementation(project(path: ":viafabricplus-api", configuration: "namedElements"))
include implementation(project(path: ":viafabricplus-visual-changes", configuration: "namedElements"))
include implementation(project(path: ":viafabricplus-visuals", configuration: "namedElements"))

// Will be removed in future versions
include implementation(project(":viafabricplus-api-legacy"))
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ includeBuild("build-logic")
setupViaSubproject("api")
setupViaSubproject("api-legacy")
setupViaSubproject("generator-tools")
setupViaSubproject("visual-changes")
setupViaSubproject("visuals")

void setupViaSubproject(String name) {
var pName = "viafabricplus-" + name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@

package com.viaversion.viafabricplus;

import com.viaversion.viafabricplus.api.entrypoint.ViaFabricPlusLoadEntrypoint;
import com.viaversion.viafabricplus.api.events.ChangeProtocolVersionCallback;
import com.viaversion.viafabricplus.api.events.LoadingCycleCallback;
import com.viaversion.viafabricplus.api.ViaFabricPlusBase;
import com.viaversion.viafabricplus.api.events.LoadingCycleCallback;
import com.viaversion.viafabricplus.api.settings.SettingGroup;
import com.viaversion.viafabricplus.base.Events;
import com.viaversion.viafabricplus.base.overriding_jars.ClassLoaderPriorityUtil;
import com.viaversion.viafabricplus.features.item.filter_creative_tabs.ItemRegistryDiff;
import com.viaversion.viafabricplus.features.item.negative_items.NegativeItemUtil;
import com.viaversion.viafabricplus.injection.access.base.IClientConnection;
import com.viaversion.viafabricplus.injection.access.base.IServerInfo;
import com.viaversion.viafabricplus.protocoltranslator.translator.ItemTranslator;
import com.viaversion.viafabricplus.util.ChatUtil;
import com.viaversion.viafabricplus.base.Events;
import com.viaversion.viafabricplus.base.sync_tasks.SyncTasks;
import com.viaversion.viafabricplus.save.SaveManager;
import com.viaversion.viafabricplus.screen.impl.ProtocolSelectionScreen;
Expand Down Expand Up @@ -102,6 +104,9 @@ public final class ViaFabricPlusImpl implements ViaFabricPlusBase {

public void init() {
ViaFabricPlus.init(this);
FabricLoader.getInstance().getEntrypointContainers("viafabricplus", ViaFabricPlusLoadEntrypoint.class).forEach(container -> {
container.getEntrypoint().onPlatformLoad(this);
});

// Create the directory if it doesn't exist
if (!Files.exists(path)) {
Expand Down Expand Up @@ -133,6 +138,7 @@ public void init() {
loadingFuture.join();
SaveManager.INSTANCE.postInit();
});
Events.LOADING_CYCLE.invoker().onLoadCycle(LoadingCycleCallback.LoadingCycle.FINAL_LOAD);
}

// --------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -262,4 +268,5 @@ public boolean itemExistsInConnection(net.minecraft.item.Item item) {
public int getStackCount(ItemStack stack) {
return NegativeItemUtil.getCount(stack);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ public final class Events {
}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,36 @@

import com.viaversion.viafabricplus.api.events.LoadingCycleCallback;
import com.viaversion.viafabricplus.base.Events;
import com.viaversion.viafabricplus.settings.impl.VisualSettings;
import com.viaversion.viafabricplus.features.block.CollisionShapes;
import com.viaversion.viafabricplus.features.cpe_extensions.CPEAdditions;
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.filter_non_existing_characters.UnicodeFontFix1_12_2;
import com.viaversion.viafabricplus.features.ui.armor_hud.ArmorHudEmulation1_8;
import com.viaversion.viafabricplus.features.ui.classic_creative_menu.GridItemSelectionScreen;
import com.viaversion.viafabricplus.features.entity.EntityDimensionDiff;
import com.viaversion.viafabricplus.features.entity.enchantment_attributes.EnchantmentAttributesEmulation1_20_6;
import com.viaversion.viafabricplus.base.sync_tasks.DataCustomPayload;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.MinecraftClient;
import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;

public final class FeaturesLoading {

static {
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) {
EntityDimensionDiff.init();
EnchantmentAttributesEmulation1_20_6.init();
ArmorHudEmulation1_8.init();
}
});

Events.CHANGE_PROTOCOL_VERSION.register((oldVersion, newVersion) -> MinecraftClient.getInstance().execute(() -> {
VisualSettings.INSTANCE.filterNonExistingGlyphs.onValueChanged();
CollisionShapes.reloadBlockShapes();

if (newVersion.olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
GridItemSelectionScreen.INSTANCE.itemGrid = null;
}
if (newVersion.olderThanOrEqualTo(ProtocolVersion.v1_11_1)) {
Recipes1_11_2.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
package com.viaversion.viafabricplus.injection.mixin.base;

import com.viaversion.viafabricplus.ViaFabricPlusImpl;
import com.viaversion.viafabricplus.api.events.LoadingCycleCallback;
import com.viaversion.viafabricplus.base.Events;
import net.minecraft.client.main.Main;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -35,9 +33,7 @@ public abstract class MixinMain {

@Inject(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Util;startTimerHack()V"))
private static void bootstrap(CallbackInfo ci) {
Events.LOADING_CYCLE.invoker().onLoadCycle(LoadingCycleCallback.LoadingCycle.INITIAL_LOAD);
ViaFabricPlusImpl.INSTANCE.init();
Events.LOADING_CYCLE.invoker().onLoadCycle(LoadingCycleCallback.LoadingCycle.FINAL_LOAD);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.ui;

import com.google.common.collect.Lists;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.viaversion.viafabricplus.injection.access.base.IServerInfo;
import com.viaversion.viafabricplus.settings.impl.GeneralSettings;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerServerListWidget;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.text.Text;
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 java.util.ArrayList;
import java.util.List;

@Mixin(MultiplayerServerListWidget.ServerEntry.class)
public abstract class MixinMultiplayerServerListWidget_ServerEntry {

@Shadow @Final private ServerInfo server;

@WrapOperation(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;setTooltip(Lnet/minecraft/text/Text;)V"))
private void drawTranslatingState(MultiplayerScreen instance, Text text, Operation<Void> original) {
final List<Text> tooltips = new ArrayList<>();
tooltips.add(text);
if (GeneralSettings.INSTANCE.showAdvertisedServerVersion.getValue()) {
final ProtocolVersion version = ((IServerInfo) server).viaFabricPlus$translatingVersion();
if (version != null) {
tooltips.add(Text.translatable("base.viafabricplus.via_translates_to", version.getName() + " (" + version.getOriginalVersion() + ")"));
tooltips.add(Text.translatable("base.viafabricplus.server_version", server.version.getString() + " (" + server.protocolVersion + ")"));
}
}
instance.setTooltip(Lists.transform(tooltips, Text::asOrderedText));
}

}
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.ui.book_edit_page_limitations;
package com.viaversion.viafabricplus.injection.mixin.features.book_edit_page_limitations;

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 @@ -36,7 +36,6 @@
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import com.viaversion.viafabricplus.protocoltranslator.impl.provider.viaversion.ViaFabricPlusHandItemProvider;
import com.viaversion.viafabricplus.protocoltranslator.translator.ItemTranslator;
import com.viaversion.viafabricplus.settings.impl.VisualSettings;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.SnowBlock;
Expand Down Expand Up @@ -326,13 +325,6 @@ private void removeClickActions(int syncId, int slotId, int button, SlotActionTy
}
}

@Inject(method = "hasExperienceBar", at = @At("HEAD"), cancellable = true)
private void removeExperienceBar(CallbackInfoReturnable<Boolean> cir) {
if (VisualSettings.INSTANCE.hideModernHUDElements.isEnabled()) {
cir.setReturnValue(false);
}
}

@Unique
private boolean viaFabricPlus$extinguishFire(BlockPos blockPos, final Direction direction) {
blockPos = blockPos.offset(direction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.llamalad7.mixinextras.sugar.Local;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import com.viaversion.viafabricplus.settings.impl.VisualSettings;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.DownloadingTerrainScreen;
Expand Down Expand Up @@ -214,11 +213,6 @@ private void fixPlayerListOrdering(MinecraftClient client, ClientConnection clie
}
}

@Redirect(method = "onGameJoin", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;isSecureChatEnforced()Z"))
private boolean removeSecureChatWarning(ClientPlayNetworkHandler instance) {
return isSecureChatEnforced() || VisualSettings.INSTANCE.disableSecureChatWarning.isEnabled();
}

@SuppressWarnings({"InvalidInjectorMethodSignature"})
@ModifyConstant(method = "onEntityPassengersSet", constant = @Constant(classValue = AbstractBoatEntity.class))
private Class<?> dontChangeYawWhenMountingBoats(Object entity, Class<?> boatClass) {
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.mixin.features.ui.sign_editor_reach;
package com.viaversion.viafabricplus.injection.mixin.features.sign_editor_reach;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
Expand Down
Loading

0 comments on commit 10bcd40

Please sign in to comment.