Skip to content

Commit

Permalink
Recoded and improved even more ™️
Browse files Browse the repository at this point in the history
- Added former contributor to author list as well
- Cleanup block changes from RaphiMC's last commit
- Fixed some block related issues
- Conditionally load IP-Next compat mixin
- Made all Mixins abstract and methods private

This commit is the initial commit to clean up some fundamental issues of VFP since its release:
- Actually start with having a package structure to group mixins
- Don't over-engineer debug/information system but keep it simple as it's only debugging
- Renamed definition package to fixes to address its purpose
- Start with creating proper packages for fixes
- Start with documenting the source code tree so new contributors understand what we're doing
  • Loading branch information
FlorianMichael committed Nov 25, 2023
1 parent 472289b commit a50dc89
Show file tree
Hide file tree
Showing 220 changed files with 981 additions and 1,313 deletions.
2 changes: 1 addition & 1 deletion .github/DEVELOPER_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final VersionRange range = ItemReleaseVersionDefinition.INSTANCE.getItemMap().ge
#### Creating own settings for the settings screen:
```java
public class ExampleSettingGroup extends SettingGroup {
public final static ExampleSettingGroup INSTANCE = new ExampleSettingGroup();
public static final ExampleSettingGroup INSTANCE = new ExampleSettingGroup();

public final BooleanSetting test = new BooleanSetting("Test", false);

Expand Down
16 changes: 9 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ base {
}

configurations {
jij
jij // jar in jar configuration
}

repositories {
Expand Down Expand Up @@ -42,12 +42,14 @@ loom {
}

dependencies {
// Minecraft/Fabric
// Minecraft/Fabric and mods
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"

modCompileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"

// ViaVersion Libraries
jij "com.viaversion:viaversion-common:${project.viaversion_version}"
jij ("com.viaversion:viabackwards-common:${project.viabackwards_version}") {
Expand Down Expand Up @@ -75,18 +77,18 @@ dependencies {
exclude group: "com.google.code.gson", module: "gson"
exclude group: "org.slf4j", module: "slf4j-api"
}
jij("org.cloudburstmc.netty:netty-transport-raknet:${project.raknet_transport_version}") {
exclude group: "io.netty"
}

// Lenni0451 Libraries
jij "net.lenni0451:Reflect:${project.reflect_version}"

// Misc Libraries
modCompileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}"
jij(annotationProcessor("com.github.llamalad7.mixinextras:mixinextras-fabric:${project.mixin_extras_version}"))
jij("org.cloudburstmc.netty:netty-transport-raknet:${project.raknet_transport_version}") {
exclude group: "io.netty"
}
jij "de.florianmichael:Classic4J:${project.classic4j_version}"
jij(annotationProcessor("com.github.llamalad7.mixinextras:mixinextras-fabric:${project.mixin_extras_version}"))

// Fabric's jar in jar system doesn't support transitive dependencies, so we have to manually add them
afterEvaluate {
configurations.jij.incoming.resolutionResult.allDependencies {
dependencies.include(dependencies.implementation(requested.toString()))
Expand Down
41 changes: 16 additions & 25 deletions src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import de.florianmichael.viafabricplus.definition.ClientsideFixes;
import de.florianmichael.viafabricplus.definition.account.BedrockAccountHandler;
import de.florianmichael.viafabricplus.definition.account.ClassiCubeAccountHandler;
import de.florianmichael.viafabricplus.definition.classic.CustomClassicProtocolExtensions;
import de.florianmichael.viafabricplus.definition.classic.screen.ClassicItemSelectionScreen;
import de.florianmichael.viafabricplus.event.FinishMinecraftLoadCallback;
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.event.PostGameLoadCallback;
import de.florianmichael.viafabricplus.event.PreLoadCallback;
import de.florianmichael.viafabricplus.information.InformationSystem;
import de.florianmichael.viafabricplus.mappings.CharacterMappings;
import de.florianmichael.viafabricplus.mappings.ItemReleaseVersionMappings;
import de.florianmichael.viafabricplus.mappings.PackFormatsMappings;
Expand Down Expand Up @@ -61,27 +60,24 @@
*
* TODO | Migration v3
* - Make recipe fixes dynamic instead of a data dump in java classes
* - Make mixin injection methods private
* - Make mixins abstract
* - Rename all methods
* - Use ViaProxy config patch for some clientside fixes options (Remove ViaFabricPlusVLViaConfig)
* - Is de.florianmichael.viafabricplus.injection.mixin.jsonwebtoken.* still needed?
* - Apply MixinAutoRefillHandler_ItemSlotMonitor only when mod is actually installed
* - Make block shapes static
* - Remove information package / system
* - 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
*/
public class ViaFabricPlus {

public final static Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public final static Logger LOGGER = LogManager.getLogger("ViaFabricPlus");
public final static File RUN_DIRECTORY = new File("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 final static ViaFabricPlus INSTANCE = new ViaFabricPlus();
public static final ViaFabricPlus INSTANCE = new ViaFabricPlus();

private final SettingsSystem settingsSystem = new SettingsSystem();
private final InformationSystem informationSystem = new InformationSystem();

public void init() {
public void bootstrap() {
if (!RUN_DIRECTORY.exists()) {
RUN_DIRECTORY.mkdir();
}
Expand All @@ -108,13 +104,12 @@ public void init() {
ProtocolHack.init();

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

// General settings
settingsSystem.init();
informationSystem.init();

// Version related mappings
PackFormatsMappings.load();
Expand All @@ -125,8 +120,4 @@ public void init() {
public SettingsSystem getSettingsSystem() {
return settingsSystem;
}

public InformationSystem getInformationSystem() {
return informationSystem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
/**
* This event is fired when the user disconnects from a server.
*/
public interface DisconnectConnectionCallback {
public interface DisconnectCallback {

Event<DisconnectConnectionCallback> EVENT = EventFactory.createArrayBacked(DisconnectConnectionCallback.class, listeners -> () -> {
for (DisconnectConnectionCallback listener : listeners) {
Event<DisconnectCallback> EVENT = EventFactory.createArrayBacked(DisconnectCallback.class, listeners -> () -> {
for (DisconnectCallback listener : listeners) {
listener.onDisconnect();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
/**
* This event is fired when Minecraft's loading tree is finished. This should be at the end of the {@link net.minecraft.client.MinecraftClient} constructor
*/
public interface FinishMinecraftLoadCallback {
public interface PostGameLoadCallback {

Event<FinishMinecraftLoadCallback> EVENT = EventFactory.createArrayBacked(FinishMinecraftLoadCallback.class, listeners -> () -> {
for (FinishMinecraftLoadCallback listener : listeners) {
listener.onFinishMinecraftLoad();
Event<PostGameLoadCallback> EVENT = EventFactory.createArrayBacked(PostGameLoadCallback.class, listeners -> () -> {
for (PostGameLoadCallback listener : listeners) {
listener.postGameLoad();
}
});

void onFinishMinecraftLoad();
void postGameLoad();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.definition;
package de.florianmichael.viafabricplus.fixes;

import de.florianmichael.viafabricplus.definition.model.BoatModel_1_8;
import de.florianmichael.viafabricplus.fixes.model.BoatModel_1_8;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexConsumerProvider;
Expand All @@ -32,7 +32,7 @@
import net.minecraft.util.math.RotationAxis;

public class BoatRenderer_1_8 extends EntityRenderer<BoatEntity> {
private final static Identifier TEXTURE = new Identifier("viafabricplus", "textures/boat_1_8.png");
private static final Identifier TEXTURE = new Identifier("viafabricplus", "textures/boat_1_8.png");
private final BoatModel_1_8 model;

public BoatRenderer_1_8(EntityRendererFactory.Context ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.definition;
package de.florianmichael.viafabricplus.fixes;

import de.florianmichael.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
Expand All @@ -37,7 +37,7 @@
import java.util.function.Consumer;

public class ClientPlayerInteractionManager1_18_2 {
public final static Consumer<PacketByteBuf> OLD_PACKET_HANDLER = data -> {
public static final Consumer<PacketByteBuf> OLD_PACKET_HANDLER = data -> {
try {
final var pos = data.readBlockPos();
final var blockState = Block.STATE_IDS.get(BlockStateTranslator.translateBlockState1_18(data.readVarInt()));
Expand All @@ -50,7 +50,7 @@ public class ClientPlayerInteractionManager1_18_2 {
}
};

private final static Object2ObjectLinkedOpenHashMap<Pair<BlockPos, PlayerActionC2SPacket.Action>, PositionAndRotation> UN_ACKED_ACTIONS = new Object2ObjectLinkedOpenHashMap<>();
private static final Object2ObjectLinkedOpenHashMap<Pair<BlockPos, PlayerActionC2SPacket.Action>, PositionAndRotation> UN_ACKED_ACTIONS = new Object2ObjectLinkedOpenHashMap<>();

public static void trackBlockAction(final PlayerActionC2SPacket.Action action, final BlockPos blockPos) {
final var player = MinecraftClient.getInstance().player;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.definition;
package de.florianmichael.viafabricplus.fixes;

import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType;
import de.florianmichael.viafabricplus.event.ChangeProtocolVersionCallback;
import de.florianmichael.viafabricplus.event.FinishMinecraftLoadCallback;
import de.florianmichael.viafabricplus.event.PostGameLoadCallback;
import de.florianmichael.viafabricplus.event.LoadClassicProtocolExtensionCallback;
import de.florianmichael.viafabricplus.injection.MixinPlugin;
import de.florianmichael.viafabricplus.injection.VFPMixinPlugin;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down Expand Up @@ -55,30 +55,30 @@ public class ClientsideFixes {
/**
* Legacy versions do not support SRV records, so we need to resolve them manually
*/
public final static VersionRange LEGACY_SRV_RESOLVE = VersionRange.andOlder(VersionEnum.r1_2_4tor1_2_5).add(VersionRange.single(VersionEnum.bedrockLatest));
public static final VersionRange LEGACY_SRV_RESOLVE = VersionRange.andOlder(VersionEnum.r1_2_4tor1_2_5).add(VersionRange.single(VersionEnum.bedrockLatest));

/**
* Contains the armor points of all armor items in legacy versions (<= 1.8.x)
*/
private final static Map<Item, Integer> LEGACY_ARMOR_POINTS = new HashMap<>();
private static final Map<Item, Integer> LEGACY_ARMOR_POINTS = new HashMap<>();

/**
* 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 final static Map<String, Consumer<PacketByteBuf>> PENDING_EXECUTION_TASKS = new ConcurrentHashMap<>();
private static final Map<String, Consumer<PacketByteBuf>> PENDING_EXECUTION_TASKS = new ConcurrentHashMap<>();

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

/**
* The current chat limit
*/
private static int currentChatLimit = 256;

public static void init() {
FinishMinecraftLoadCallback.EVENT.register(() -> {
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,
Items.CHAINMAIL_HELMET, Items.CHAINMAIL_CHESTPLATE, Items.CHAINMAIL_LEGGINGS, Items.CHAINMAIL_BOOTS,
Expand Down Expand Up @@ -125,7 +125,7 @@ public static void init() {
currentChatLimit = 256;
}

if (!MixinPlugin.DASH_LOADER_PRESENT) {
if (!VFPMixinPlugin.DASH_LOADER_PRESENT) {
// Reloads all font storages to fix the font renderer
for (FontStorage storage : MinecraftClient.getInstance().fontManager.fontStorages.values()) {
storage.glyphRendererCache.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.definition;
package de.florianmichael.viafabricplus.fixes;

import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.entity.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.definition;
package de.florianmichael.viafabricplus.fixes;

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

package de.florianmichael.viafabricplus.definition;
package de.florianmichael.viafabricplus.fixes;

import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.libs.gson.JsonElement;
Expand All @@ -35,7 +35,7 @@
import java.util.function.Consumer;

public class TripleChestHandler1_13_2 {
public final static Consumer<PacketByteBuf> TRIPLE_CHEST_HANDLER = data -> {
public static final Consumer<PacketByteBuf> TRIPLE_CHEST_HANDLER = data -> {
final var byteBuf = data.asByteBuf();

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

package de.florianmichael.viafabricplus.definition.account;
package de.florianmichael.viafabricplus.fixes.account;

import com.google.gson.JsonObject;
import de.florianmichael.viafabricplus.ViaFabricPlus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.definition.account;
package de.florianmichael.viafabricplus.fixes.account;

import com.google.gson.JsonObject;
import de.florianmichael.classic4j.model.classicube.account.CCAccount;
import de.florianmichael.viafabricplus.event.DisconnectConnectionCallback;
import de.florianmichael.viafabricplus.event.DisconnectCallback;
import de.florianmichael.viafabricplus.protocolhack.provider.vialegacy.ViaFabricPlusClassicMPPassProvider;
import de.florianmichael.viafabricplus.util.FileSaver;

Expand All @@ -41,7 +41,7 @@ public static void create() {
public ClassiCubeAccountHandler() {
super("classicube.account");

DisconnectConnectionCallback.EVENT.register(() -> ViaFabricPlusClassicMPPassProvider.classiCubeMPPass = null);
DisconnectCallback.EVENT.register(() -> ViaFabricPlusClassicMPPassProvider.classiCubeMPPass = null);
}

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

package de.florianmichael.viafabricplus.definition.classic;
package de.florianmichael.viafabricplus.fixes.classic;

import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.definition.classic;
package de.florianmichael.viafabricplus.fixes.classic;

import com.viaversion.viaversion.api.connection.UserConnection;
import de.florianmichael.viafabricplus.definition.classic.screen.ClassicItemSelectionScreen;
import de.florianmichael.viafabricplus.fixes.classic.screen.ClassicItemSelectionScreen;
import de.florianmichael.viafabricplus.event.LoadClassicProtocolExtensionCallback;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import io.netty.buffer.ByteBuf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.definition.classic.command;
package de.florianmichael.viafabricplus.fixes.classic.command;

import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.api.command.ViaSubCommand;
Expand All @@ -35,6 +35,6 @@ public void sendMessage(final ViaCommandSender sender, final String message) {
}

public UserConnection getUser() {
return ProtocolHack.getMainUserConnection();
return ProtocolHack.getPlayNetworkUserConnection();
}
}
Loading

0 comments on commit a50dc89

Please sign in to comment.