Fix forge builds

Server side is not functional yet
This commit is contained in:
s809
2024-01-02 20:47:11 +05:00
parent 27446965db
commit 03ec333a26
5 changed files with 166 additions and 50 deletions
+2 -2
View File
@@ -35,8 +35,8 @@ build:
# this both runs the unit tests and assembles the code
- ./gradlew clean -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
- ./gradlew fabric:build -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
# - ./gradlew build -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
# - ./gradlew mergeJars -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
- ./gradlew build -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
- ./gradlew mergeJars -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
artifacts:
name: "NightlyBuild_${MC_VER}-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_TIMESTAMP}"
paths:
@@ -33,6 +33,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapp
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.coreapi.ModInfo;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.resources.ResourceLocation;
@@ -52,8 +53,20 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
#if MC_VER >= MC_1_20_2
import net.minecraftforge.network.Channel;
import net.minecraftforge.network.ChannelBuilder;
import net.minecraftforge.network.SimpleChannel;
#elif MC_VER >= MC_1_18_2
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.simple.SimpleChannel;
#elif MC_VER >= MC_1_17_1
import net.minecraftforge.fmllegacy.network.NetworkRegistry;
import net.minecraftforge.fmllegacy.network.simple.SimpleChannel;
#else // < 1.17.1
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.simple.SimpleChannel;
#endif
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;
@@ -65,6 +78,8 @@ import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.lwjgl.opengl.GL32;
import java.util.function.Predicate;
/**
* This handles all events sent to the client,
* and is the starting point for most of the mod.
@@ -241,45 +256,33 @@ public class ForgeClientProxy
/** @param event this is just to ensure the event is called at the right time, if it is called outside the {@link FMLClientSetupEvent} event, the binding may fail */
public static void setupNetworkingListeners(FMLClientSetupEvent event)
{
multiversePluginChannel = NetworkRegistry.newSimpleChannel(
new ResourceLocation(ModInfo.NETWORKING_RESOURCE_NAMESPACE, ModInfo.MULTIVERSE_PLUGIN_NAMESPACE),
// network protocol version
() -> ModInfo.MULTIVERSE_PLUGIN_PROTOCOL_VERSION +"",
// client accepted versions
ForgeClientProxy::isReceivedProtocolVersionAcceptable,
// server accepted versions
ForgeClientProxy::isReceivedProtocolVersionAcceptable
);
multiversePluginChannel.registerMessage(0/*should be incremented for each simple channel we listen to*/, ByteBuf.class,
// encoder
(pack, friendlyByteBuf) -> { },
// decoder
(friendlyByteBuf) -> friendlyByteBuf.asByteBuf(),
// message consumer
(nettyByteBuf, contextRef) ->
#if MC_VER >= MC_1_20_2
Channel.VersionTest versionTest = (status, version)
-> status != Channel.VersionTest.Status.PRESENT || version == ModInfo.MULTIVERSE_PLUGIN_PROTOCOL_VERSION;
multiversePluginChannel = ChannelBuilder.named(new ResourceLocation(ModInfo.NETWORKING_RESOURCE_NAMESPACE, ModInfo.MULTIVERSE_PLUGIN_NAMESPACE))
.networkProtocolVersion(ModInfo.MULTIVERSE_PLUGIN_PROTOCOL_VERSION)
.serverAcceptedVersions(versionTest)
.clientAcceptedVersions(versionTest)
.simpleChannel();
multiversePluginChannel.messageBuilder(ByteBuf.class, 0)
.decoder(FriendlyByteBuf::asReadOnly)
.consumerNetworkThread((nettyByteBuf, contextRef) ->
{
ClientApi.INSTANCE.serverMessageReceived(nettyByteBuf);
contextRef.get().setPacketHandled(true);
}
);
}
public static boolean isReceivedProtocolVersionAcceptable(String versionString)
{
if (versionString.toLowerCase().contains("allowvanilla"))
contextRef.setPacketHandled(true);
})
.add();
#else // < 1.20.2
Predicate<String> versionTest = versionString ->
{
// allow using networking on vanilla servers
return true;
}
else if (versionString.toLowerCase().contains("absent"))
{
// allow using networking even if DH isn't installed on the server
return true;
}
else
{
// DH is installed on the server, check if the version is valid to use
if (versionString.equals(NetworkRegistry.ABSENT) || versionString.equals(NetworkRegistry.ACCEPTVANILLA))
{
// allow using networking on vanilla servers or if DH isn't installed on the server
return true;
}
try
{
int version = Integer.parseInt(versionString);
@@ -289,11 +292,34 @@ public class ForgeClientProxy
{
return false;
}
}
};
multiversePluginChannel = NetworkRegistry.newSimpleChannel(
new ResourceLocation(ModInfo.NETWORKING_RESOURCE_NAMESPACE, ModInfo.MULTIVERSE_PLUGIN_NAMESPACE),
// network protocol version
() -> ModInfo.MULTIVERSE_PLUGIN_PROTOCOL_VERSION +"",
// client accepted versions
versionTest,
// server accepted versions
versionTest
);
multiversePluginChannel.registerMessage(0/*should be incremented for each simple channel we listen to*/, ByteBuf.class,
// encoder
(pack, friendlyByteBuf) -> { },
// decoder
FriendlyByteBuf::asReadOnly,
// message consumer
(nettyByteBuf, contextRef) ->
{
ClientApi.INSTANCE.serverMessageReceived(nettyByteBuf);
contextRef.get().setPacketHandled(true);
}
);
#endif
}
//===========//
// rendering //
//===========//
@@ -26,6 +26,8 @@ import com.seibel.distanthorizons.common.forge.LodForgeMethodCaller;
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
import com.seibel.distanthorizons.common.wrappers.gui.GetConfigScreen;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftClientWrapper;
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftDedicatedServerWrapper;
import com.seibel.distanthorizons.core.config.eventHandlers.presets.ThreadPresetConfigEventHandler;
import com.seibel.distanthorizons.core.jar.ModJarInfo;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.AbstractOptifineAccessor;
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
@@ -42,6 +44,7 @@ import net.minecraft.core.Direction;
#if MC_VER >= MC_1_19_2
import net.minecraft.util.RandomSource;
#endif
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.world.level.ColorResolver;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Block;
@@ -50,6 +53,13 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.*;
#if MC_VER == MC_1_16_5
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
#elif MC_VER == MC_1_17_1
import net.minecraftforge.fmlserverevents.FMLServerStartingEvent;
#else
import net.minecraftforge.event.server.ServerStartingEvent;
#endif
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
#if MC_VER < MC_1_17_1
import net.minecraftforge.fml.ExtensionPoint;
@@ -95,7 +105,6 @@ public class ForgeMain implements LodForgeMethodCaller
public ForgeMain()
{
DependencySetup.createClientBindings();
// initDedicated(null);
// initDedicated(null);
@@ -106,6 +115,7 @@ public class ForgeMain implements LodForgeMethodCaller
private void initClient(final FMLClientSetupEvent event)
{
DependencySetup.createClientBindings();
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
LOGGER.info("Initializing Mod");
@@ -152,13 +162,44 @@ public class ForgeMain implements LodForgeMethodCaller
private void initDedicated(final FMLDedicatedServerSetupEvent event)
{
// DependencySetup.createServerBindings();
// initCommon();
// server_proxy = new ForgeServerProxy(true);
// MinecraftForge.EVENT_BUS.register(server_proxy);
//
postInitCommon();
DependencySetup.createServerBindings();
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
LOGGER.info("Initializing Mod");
LodCommonMain.startup(this);
ForgeDependencySetup.createInitialBindings();
LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
// Print git info (Useful for dev builds)
//LOGGER.info("DH Branch: " + ModJarInfo.Git_Branch);
//LOGGER.info("DH Commit: " + ModJarInfo.Git_Commit);
//LOGGER.info("DH Jar Build Source: " + ModJarInfo.Build_Source);
// FIXME this prevents returning uninitialized Config values
// resulting from a circular reference mid-initialization in a static class
//noinspection ResultOfMethodCallIgnored
ThreadPresetConfigEventHandler.INSTANCE.toString();
server_proxy = new ForgeServerProxy(true);
MinecraftForge.EVENT_BUS.register(server_proxy);
LOGGER.info(ModInfo.READABLE_NAME + " Initialized");
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
#if MC_VER >= MC_1_18_2
MinecraftForge.EVENT_BUS.addListener((ServerStartingEvent e) -> {
MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer)e.getServer();
#else
MinecraftForge.EVENT_BUS.addListener((FMLServerStartingEvent e) -> {
MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer)e.getServer();
#endif
// Init config
// The reason im initialising in this rather than the post init process is cus im using this for the auto updater
LodCommonMain.initConfig();
postInitCommon();
});
}
private void postInitCommon()
@@ -6,6 +6,14 @@ import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
#if MC_VER >= MC_1_18_2
import net.minecraftforge.internal.BrandingControl;
#elif MC_VER >= MC_1_17_1
import net.minecraftforge.fmllegacy.BrandingControl;
#else // < 1.17.1
import net.minecraftforge.fml.BrandingControl;
#endif
import java.util.List;
import java.util.Set;
@@ -19,8 +27,16 @@ public class ForgeMixinPlugin implements IMixinConfigPlugin
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName)
{
if (!ClientBrandRetriever.getClientModName().equals("forge"))
return false;
try
{
if (!ClientBrandRetriever.getClientModName().equals("forge"))
return false;
}
catch (RuntimeException e)
{
if (!BrandingControl.getServerBranding().equals("forge"))
return false;
}
if (mixinClassName.contains(".mods."))
{ // If the mixin wants to go into a mod then we check if that mod is loaded or not
Executable
+33
View File
@@ -0,0 +1,33 @@
#!/bin/bash
# Usage: ./verifyall.sh [forge|fabric|whatever to put before ":classes"]
if [ -n "$1" ]; then
prefix="$1:"
fi
z
clear
trap "echo; exit" INT
declare -a completed_builds
for version in $(ls ./versionProperties/); do
version=${version%".properties"}
result=""
if ./gradlew "$prefix"classes -PmcVer=$version; then
result+="\e[1;32m"
else
result+="\e[1;31m"
fi
result+=$version
result+="\e[0m"
completed_builds+=($result)
done
./gradlew clean
./gradlew classes
echo
echo "Build results:"
echo -e "${completed_builds[*]}"