Skip to content

Commit

Permalink
Forge 1.20.2 (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Nov 21, 2023
1 parent c672948 commit 6e31341
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 71 deletions.
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ architectury {
common(rootProject.enabled_platforms.split(","))
}

ext.jei_minecraft_version = "1.19.4" /* temporary, till 1.20 releases */
ext.jei_minecraft_version = "1.20.2" /* temporary, till 1.20 releases */

dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
import net.minecraftforge.client.event.RecipesUpdatedEvent;
import net.minecraftforge.client.event.RegisterClientCommandsEvent;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.client.gui.overlay.ForgeGui;
import net.minecraftforge.client.settings.KeyConflictContext;
import net.minecraftforge.event.TagsUpdatedEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.level.LevelEvent;
import net.minecraftforge.event.server.ServerStartedEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.*;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.ModLoadingStage;
import net.minecraftforge.fml.ModLoadingWarning;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
import org.embeddedt.modernfix.ModernFixClient;
import org.embeddedt.modernfix.core.ModernFixMixinPlugin;
import org.embeddedt.modernfix.forge.config.NightConfigFixer;
import org.embeddedt.modernfix.screen.ModernFixConfigScreen;

Expand Down Expand Up @@ -52,8 +52,7 @@ private void keyBindRegister(RegisterKeyMappingsEvent event) {
}

private void onClientSetup(FMLClientSetupEvent event) {
if(false && ModernFixMixinPlugin.instance.isOptionEnabled("perf.dynamic_resources.ConnectednessCheck")
&& ModList.get().isLoaded("connectedness")) {
if(false) {
event.enqueueWork(() -> {
ModLoader.get().addWarning(new ModLoadingWarning(ModLoadingContext.get().getActiveContainer().getModInfo(), ModLoadingStage.SIDED_SETUP, "modernfix.connectedness_dynresoruces"));
});
Expand All @@ -80,7 +79,7 @@ public void onClientChat(RegisterClientCommandsEvent event) {

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onRenderOverlay(CustomizeGuiOverlayEvent.DebugText event) {
if(commonMod.brandingString != null && Minecraft.getInstance().options.renderDebug) {
if(commonMod.brandingString != null && Minecraft.getInstance().getDebugOverlay().showDebugScreen()) {
if(brandingList.size() == 0) {
brandingList.add("");
brandingList.add(commonMod.brandingString);
Expand All @@ -103,10 +102,8 @@ public void onRenderOverlay(CustomizeGuiOverlayEvent.DebugText event) {
@SubscribeEvent
public void onDisconnect(LevelEvent.Unload event) {
if(event.getLevel().isClientSide()) {
DebugScreenOverlay overlay = ObfuscationReflectionHelper.getPrivateValue(ForgeGui.class, (ForgeGui)Minecraft.getInstance().gui, "debugOverlay");
if(overlay != null) {
Minecraft.getInstance().tell(overlay::clearChunkCache);
}
DebugScreenOverlay overlay = Minecraft.getInstance().getDebugOverlay();
Minecraft.getInstance().tell(overlay::clearChunkCache);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.network.NetworkConstants;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent;
import net.minecraftforge.server.ServerLifecycleHooks;
Expand Down Expand Up @@ -49,7 +48,7 @@ public ModernFixForge() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::commonSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::registerItems);
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> MinecraftForge.EVENT_BUS.register(new ModernFixClientForge()));
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true));
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> IExtensionPoint.DisplayTest.IGNORESERVERONLY, (a, b) -> true));
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ModernFixConfig.COMMON_CONFIG);
PacketHandler.register();
ModFileScanDataDeduplicator.deduplicate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.embeddedt.modernfix.forge.mixin.core;

import net.minecraft.server.Bootstrap;
import net.minecraftforge.network.NetworkConstants;
import org.slf4j.Logger;
import net.minecraftforge.network.NetworkInitialization;
import org.embeddedt.modernfix.forge.load.ModWorkManagerQueue;
import org.embeddedt.modernfix.util.TimeFormatter;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -31,6 +31,6 @@ private static void doModernFixBootstrap(CallbackInfo ci) {
/* for https://github.com/MinecraftForge/MinecraftForge/issues/9505 */
@Inject(method = "bootStrap", at = @At("RETURN"))
private static void doClassloadHack(CallbackInfo ci) {
NetworkConstants.init();
NetworkInitialization.init();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package org.embeddedt.modernfix.forge.mixin.core;

import net.minecraft.network.Connection;
import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.network.ConnectionType;
import net.minecraftforge.network.NetworkContext;
import org.embeddedt.modernfix.forge.packet.NetworkUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(NetworkHooks.class)
@Mixin(ForgeHooks.class)
public abstract class NetworkHooksMixin {
@Shadow public static boolean isVanillaConnection(Connection manager) {
throw new AssertionError();
}

@Inject(method = "handleClientLoginSuccess", at = @At("RETURN"), remap = false)
@Inject(method = "handleClientConfigurationComplete", at = @At("RETURN"), remap = false)
private static void setVanillaGlobalFlag(Connection manager, CallbackInfo ci) {
NetworkUtils.isCurrentlyVanilla = isVanillaConnection(manager);
NetworkUtils.isCurrentlyVanilla = NetworkContext.get(manager).getType() == ConnectionType.VANILLA;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.embeddedt.modernfix.forge.mixin.perf.fast_registry_validation;

import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
import net.minecraftforge.registries.ForgeRegistry;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
Expand All @@ -10,26 +9,25 @@
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.lang.reflect.Method;
import java.util.*;
import java.util.BitSet;

@Mixin(value = ForgeRegistry.class, remap = false)
public class ForgeRegistryMixin<V> {
private static Method bitSetTrimMethod = null;
private static boolean bitSetTrimMethodRetrieved = false;

/**
* Cache the result of findMethod instead of running it multiple times.
* Null checks are not required as the surrounding code handles it already.
*/
@Redirect(method = "validateContent", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/util/ObfuscationReflectionHelper;findMethod(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"))
private Method skipMultipleRemap(Class<?> clz, String methodName, Class<?>[] params) {
if(!bitSetTrimMethodRetrieved) {
bitSetTrimMethodRetrieved = true;
bitSetTrimMethod = ObfuscationReflectionHelper.findMethod(clz, methodName, params);
}
return bitSetTrimMethod;
}
//private static Method bitSetTrimMethod = null;
//private static boolean bitSetTrimMethodRetrieved = false;

///**
// * Cache the result of findMethod instead of running it multiple times.
// * Null checks are not required as the surrounding code handles it already.
// */
//@Redirect(method = "validateContent", at = @At(value = "HEAD"))
//private Method skipMultipleRemap(Class<?> clz, String methodName, Class<?>[] params) {
// if(!bitSetTrimMethodRetrieved) {
// bitSetTrimMethodRetrieved = true;
// bitSetTrimMethod = ObfuscationReflectionHelper.findMethod(BitSet.class, methodName, params);
// }
// return bitSetTrimMethod;
//}

private int expectedNextBit = -1;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
package org.embeddedt.modernfix.forge.packet;

import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.network.Channel;
import net.minecraftforge.network.ChannelBuilder;
import net.minecraftforge.network.SimpleChannel;
import org.embeddedt.modernfix.ModernFix;
import org.embeddedt.modernfix.ModernFixClient;
import org.embeddedt.modernfix.packet.EntityIDSyncPacket;

import java.util.function.Supplier;

public class PacketHandler {
private static final String PROTOCOL_VERSION = "1";
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
new ResourceLocation(ModernFix.MODID, "main"),
() -> PROTOCOL_VERSION,
NetworkRegistry.acceptMissingOr(PROTOCOL_VERSION),
NetworkRegistry.acceptMissingOr(PROTOCOL_VERSION)
);
private static final int PROTOCOL_VERSION = 1;
public static final SimpleChannel INSTANCE = ChannelBuilder
.named(new ResourceLocation(ModernFix.MODID, "main"))
.networkProtocolVersion(PROTOCOL_VERSION)
.serverAcceptedVersions(Channel.VersionTest.ACCEPT_MISSING.or(Channel.VersionTest.exact(PROTOCOL_VERSION)))
.clientAcceptedVersions(Channel.VersionTest.ACCEPT_MISSING.or(Channel.VersionTest.exact(PROTOCOL_VERSION)))
.simpleChannel();

public static void register() {
int id = 1;
INSTANCE.registerMessage(id++, EntityIDSyncPacket.class, EntityIDSyncPacket::serialize, EntityIDSyncPacket::deserialize, PacketHandler::handleSyncPacket);
}

private static void handleSyncPacket(EntityIDSyncPacket packet, Supplier<NetworkEvent.Context> contextSupplier) {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
contextSupplier.get().enqueueWork(() -> ModernFixClient.handleEntityIDSync(packet));
contextSupplier.get().setPacketHandled(true);
});
INSTANCE.messageBuilder(EntityIDSyncPacket.class).encoder(EntityIDSyncPacket::serialize).decoder(EntityIDSyncPacket::deserialize).consumerNetworkThread((msg, ctx) -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
ctx.enqueueWork(() -> ModernFixClient.handleEntityIDSync(msg));
ctx.setPacketHandled(true);
});
}).add();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Path getGameDirectory() {
}

public void sendPacket(ServerPlayer player, Object packet) {
PacketHandler.INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), packet);
PacketHandler.INSTANCE.send(packet, PacketDistributor.PLAYER.with(player));
}

public void injectPlatformSpecificHacks() {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ mixinextras_version=0.2.0-beta.9

mod_id=modernfix
minecraft_version=1.20.2
enabled_platforms=fabric
forge_version=1.20.1-47.1.3
enabled_platforms=fabric,forge
forge_version=1.20.2-48.0.40
# parchment_version=2023.07.09
refined_storage_version=4392788
jei_version=13.1.0.2
rei_version=11.0.597
jei_version=16.0.0.28
rei_version=13.0.678
ctm_version=1.20.1-1.1.8+4
kubejs_version=1902.6.0-build.142
rhino_version=1902.2.2-build.268
Expand All @@ -20,7 +20,7 @@ supported_minecraft_versions=1.20.2
fabric_loader_version=0.14.22
fabric_api_version=0.89.2+1.20.2

continuity_version=3.0.0-beta.2+1.19.3
continuity_version=3.0.0-beta.4+1.20.2

modmenu_version=7.0.0-beta.2
diagonal_fences_version=4558828
Expand Down

0 comments on commit 6e31341

Please sign in to comment.