Skip to content

Commit

Permalink
Continue with recoding the project:
Browse files Browse the repository at this point in the history
- Added proper system for config files / saving:
  Added SaveManager and AbstractSave
  Deleted random save classes (ClassiCubeAccountHandler and BedrockAccountHandler)
- Moved data classes into proper packages
- renamed translation keys to fit english translation
- Deleted deprecated or useless settings and added new setting for optional fixes
- Changed settings system to save names instead of ordinals
- Added setting to save selected version
  • Loading branch information
FlorianMichael committed Nov 26, 2023
1 parent ae86d92 commit 34d7808
Show file tree
Hide file tree
Showing 121 changed files with 3,656 additions and 4,032 deletions.
95 changes: 35 additions & 60 deletions src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,23 @@

package de.florianmichael.viafabricplus;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import de.florianmichael.viafabricplus.event.PostGameLoadCallback;
import de.florianmichael.viafabricplus.event.PreLoadCallback;
import de.florianmichael.viafabricplus.event.LoadCallback;
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
import de.florianmichael.viafabricplus.fixes.account.BedrockAccountHandler;
import de.florianmichael.viafabricplus.fixes.account.ClassiCubeAccountHandler;
import de.florianmichael.viafabricplus.fixes.classic.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.fixes.classic.screen.ClassicItemSelectionScreen;
import de.florianmichael.viafabricplus.mappings.CharacterMappings;
import de.florianmichael.viafabricplus.mappings.ItemReleaseVersionMappings;
import de.florianmichael.viafabricplus.mappings.PackFormatsMappings;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import de.florianmichael.viafabricplus.protocolhack.util.ViaJarReplacer;
import de.florianmichael.viafabricplus.settings.SettingsSystem;
import de.florianmichael.viafabricplus.util.ClassLoaderPriorityUtil;
import de.florianmichael.viafabricplus.save.SaveManager;
import de.florianmichael.viafabricplus.settings.SettingsManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;

/*
* TODO | General
* - Make recipe fixes dynamic instead of a data dump in java classes
* - Check if relevant for protocol translation: TakeItemEntityPacket isEmpty case (1.20 -> 1.20.1 change)
* - Window interactions in <= 1.16.5 has changed and can be detected by the server
* - Entity hit boxes and eye heights has changed in almost all versions
* - Block hardness / resistance has changed in almost all versions
* - Item properties: maxDamage and stackCount?
* - Recipes for <= 1.8 are broken
* - Supported character fix should cover all versions
* - Most CTS protocol features aren't supported (see https://github.com/ViaVersion/ViaFabricPlus/issues/181)
* - Most CPE features aren't implemented correctly (see https://github.com/ViaVersion/ViaFabricPlus/issues/152)
* - Bedrock scaffolding should be added as soon as ViaBedrock supports block placement (see https://github.com/ViaVersion/ViaFabricPlus/issues/204)
Expand All @@ -58,71 +46,58 @@
* - Blit-jump is not supported in <= 1.8.9 (https://github.com/ViaVersion/ViaFabricPlus/issues/225)
*
* TODO | Migration v3
* - Make recipe fixes dynamic instead of a data dump in java classes
* - Rename all methods
* - Use ViaProxy config patch for some clientside fixes options (Remove ViaFabricPlusVLViaConfig)
* - Use ViaProxy config patch for some clientside fixes options (Remove ViaFabricPlusVLViaConfig and MixinViaLegacyConfig)
* - Re-add Debug Hud information list
* - Recode config save base to support singleton Jsons
* - Rebase fixes package / change all packages
* - Fix auto detect to not be a huge mess
* - Fix MixinAbstractDonkeyEntity
* - Boats are probably broken. Check entity height offset fix
* - Check TO DO in MixinEntity
* - Sort injection methods in fixes package by version
* - Add setting for revertOnlyPlayerCramming
* - Add setting for MixinLockableContainerBlockEntity
* - Diff ItemRegistryDiff from projects and add missing items
* - Fix third party implementations properly
*/
public class ViaFabricPlus {
private static final ViaFabricPlus instance = new ViaFabricPlus();

public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static final Logger LOGGER = LogManager.getLogger("ViaFabricPlus");
public static final File RUN_DIRECTORY = new File("ViaFabricPlus");

public static final ViaFabricPlus INSTANCE = new ViaFabricPlus();
private final Logger logger = LogManager.getLogger("ViaFabricPlus");
private final File directory = new File("ViaFabricPlus");

private final SettingsSystem settingsSystem = new SettingsSystem();
private SettingsManager settingsManager;
private SaveManager saveManager;

@SuppressWarnings("ResultOfMethodCallIgnored")
public void bootstrap() {
if (!RUN_DIRECTORY.exists()) {
RUN_DIRECTORY.mkdir();
}

// Load overriding jars first so other code can access the new classes
ViaJarReplacer.loadOverridingJars();

// PreLoad Callback (for example to register new protocols)
PreLoadCallback.EVENT.invoker().onLoad();
directory.mkdir();
ClassLoaderPriorityUtil.loadOverridingJars(directory); // Load overriding jars first so other code can access the new classes

// Classic Stuff
CustomClassicProtocolExtensions.create();
ClientsideFixes.init(); // Init clientside related fixes
ProtocolHack.init(directory); // Init ViaVersion protocol translator platform

// Account Handler
ClassiCubeAccountHandler.create();
BedrockAccountHandler.create();

// Fixes which requires to be loaded pre
ClientsideFixes.init();
CharacterMappings.load();
settingsManager = new SettingsManager();
saveManager = new SaveManager(settingsManager);
PostGameLoadCallback.EVENT.register(saveManager::init); // Has to wait for Minecraft because of the translation system usages
}

// Protocol Translator
ProtocolHack.initCommands();
ProtocolHack.init();
public static ViaFabricPlus global() {
return instance;
}

// Stuff which requires Minecraft to be initialized
PostGameLoadCallback.EVENT.register(() -> {
// Has to be loaded before the settings system in order to catch the ChangeProtocolVersionCallback call
ClassicItemSelectionScreen.create();
public Logger getLogger() {
return logger;
}

// General settings
settingsSystem.init();
public File getDirectory() {
return directory;
}

// Version related mappings
PackFormatsMappings.load();
ItemReleaseVersionMappings.create();
});
public SettingsManager getSettingsManager() {
return settingsManager;
}

public SettingsSystem getSettingsSystem() {
return settingsSystem;
public SaveManager getSaveManager() {
return saveManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
/**
* This event is fired before everything is loaded.
*/
public interface PreLoadCallback {
public interface LoadCallback {

Event<PreLoadCallback> EVENT = EventFactory.createArrayBacked(PreLoadCallback.class, listeners -> () -> {
for (PreLoadCallback listener : listeners) {
listener.onLoad();
Event<LoadCallback> EVENT = EventFactory.createArrayBacked(LoadCallback.class, listeners -> state -> {
for (LoadCallback listener : listeners) {
listener.onLoad(state);
}
});

void onLoad();
void onLoad(final State state);

enum State {
PRE, POST
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
/**
* This event is fired when ViaVersion's startup is finished.
*/
public interface FinishViaVersionStartupCallback {
public interface PostViaVersionLoadCallback {

Event<FinishViaVersionStartupCallback> EVENT = EventFactory.createArrayBacked(FinishViaVersionStartupCallback.class, listeners -> () -> {
for (FinishViaVersionStartupCallback listener : listeners) {
listener.onFinishViaVersionStartup();
Event<PostViaVersionLoadCallback> EVENT = EventFactory.createArrayBacked(PostViaVersionLoadCallback.class, listeners -> () -> {
for (PostViaVersionLoadCallback listener : listeners) {
listener.onPostViaVersionLoad();
}
});

void onFinishViaVersionStartup();
void onPostViaVersionLoad();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@
/**
* This event is fired when ViaFabricPlus has initialized its settings, and before it starts reading the values from the settings file.
*/
public interface InitializeSettingsCallback {
public interface RegisterSettingsCallback {

Event<InitializeSettingsCallback> EVENT = EventFactory.createArrayBacked(InitializeSettingsCallback.class, listeners -> () -> {
for (InitializeSettingsCallback listener : listeners) {
listener.onInitializeSettings();
Event<RegisterSettingsCallback> EVENT = EventFactory.createArrayBacked(RegisterSettingsCallback.class, listeners -> state -> {
for (RegisterSettingsCallback listener : listeners) {
listener.onInitializeSettings(state);
}
});

void onInitializeSettings();
void onInitializeSettings(final State state);

enum State {
PRE, POST
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ClientPlayerInteractionManager1_18_2 {

ClientPlayerInteractionManager1_18_2.handleBlockBreakAck(pos, blockState, action, allGood);
} catch (Exception e) {
ViaFabricPlus.LOGGER.error("Failed to read BlockBreakAck packet data", e);
ViaFabricPlus.global().getLogger().error("Failed to read BlockBreakAck packet data", e);
}
};

Expand Down Expand Up @@ -84,7 +84,7 @@ public static void handleBlockBreakAck(final BlockPos blockPos, final BlockState
}

while (UN_ACKED_ACTIONS.size() >= 50) {
ViaFabricPlus.LOGGER.error("Too many unacked block actions, dropping {}", UN_ACKED_ACTIONS.firstKey());
ViaFabricPlus.global().getLogger().error("Too many unacked block actions, dropping {}", UN_ACKED_ACTIONS.firstKey());
UN_ACKED_ACTIONS.removeFirst();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import de.florianmichael.viafabricplus.event.ChangeProtocolVersionCallback;
import de.florianmichael.viafabricplus.event.PostGameLoadCallback;
import de.florianmichael.viafabricplus.event.LoadClassicProtocolExtensionCallback;
import de.florianmichael.viafabricplus.injection.VFPMixinPlugin;
import de.florianmichael.viafabricplus.fixes.classic.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.fixes.classic.screen.ClassicItemSelectionScreen;
import de.florianmichael.viafabricplus.injection.ViaFabricPlusMixinPlugin;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -78,6 +80,8 @@ public class ClientsideFixes {
private static int currentChatLimit = 256;

public static void init() {
CustomClassicProtocolExtensions.create();

PostGameLoadCallback.EVENT.register(() -> {
// Loads the armor points of all armor items in legacy versions (<= 1.8.x)
for (Item armorItem : Arrays.asList(Items.LEATHER_HELMET, Items.LEATHER_CHESTPLATE, Items.LEATHER_BOOTS,
Expand All @@ -104,7 +108,7 @@ public static void init() {
});

// Reloads some clientside stuff when the protocol version changes
ChangeProtocolVersionCallback.EVENT.register(protocolVersion -> MinecraftClient.getInstance().execute(() -> {
ChangeProtocolVersionCallback.EVENT.register((oldVersion, newVersion) -> MinecraftClient.getInstance().execute(() -> {
if (MinecraftClient.getInstance() == null) return;

// Reloads all bounding boxes
Expand All @@ -115,23 +119,27 @@ public static void init() {
}

// Calculates the current chat limit, since it changes depending on the protocol version
if (protocolVersion.isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
if (newVersion.isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
currentChatLimit = 64 - (MinecraftClient.getInstance().getSession().getUsername().length() + 2);
} else if (protocolVersion.equals(VersionEnum.bedrockLatest)) {
} else if (newVersion.equals(VersionEnum.bedrockLatest)) {
currentChatLimit = 512;
} else if (protocolVersion.isOlderThanOrEqualTo(VersionEnum.r1_9_3tor1_9_4)) {
} else if (newVersion.isOlderThanOrEqualTo(VersionEnum.r1_9_3tor1_9_4)) {
currentChatLimit = 100;
} else {
currentChatLimit = 256;
}

if (!VFPMixinPlugin.DASH_LOADER_PRESENT) {
if (!ViaFabricPlusMixinPlugin.DASH_LOADER_PRESENT) {
// Reloads all font storages to fix the font renderer
for (FontStorage storage : MinecraftClient.getInstance().fontManager.fontStorages.values()) {
storage.glyphRendererCache.clear();
storage.glyphCache.clear();
}
}

if (newVersion.isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
ClassicItemSelectionScreen.INSTANCE.reload(newVersion, false);
}
}));

// Calculates the current chat limit, since it changes depending on the protocol version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class TripleChestHandler1_13_2 {
try {
TripleChestHandler1_13_2.handleTripleChestHandler(Type.SHORT.readPrimitive(byteBuf), Type.COMPONENT.read(byteBuf), Type.SHORT.readPrimitive(byteBuf));
} catch (Exception e) {
ViaFabricPlus.LOGGER.error("Failed to open custom ScreenHandler with dimension 9xN", e);
ViaFabricPlus.global().getLogger().error("Failed to open custom ScreenHandler with dimension 9xN", e);
}
};

Expand Down

This file was deleted.

Loading

0 comments on commit 34d7808

Please sign in to comment.