Compare commits
16 Commits
serverside
..
stable
| Author | SHA1 | Date | |
|---|---|---|---|
| b6b108a287 | |||
| 2a37bec8ff | |||
| f0f864d824 | |||
| 5abbff42d8 | |||
| 53e2c4f806 | |||
| cb4c32e0a9 | |||
| c620086ed1 | |||
| 513cecf318 | |||
| 749921b436 | |||
| 0d565895e2 | |||
| 2c6849a0fd | |||
| 4d53ec5b64 | |||
| 4467af4798 | |||
| d3f953686a | |||
| 67901d82c5 | |||
| 013fbf638a |
+2
-2
@@ -538,7 +538,7 @@ ij_groovy_wrap_chain_calls_after_dot = false
|
||||
ij_groovy_wrap_long_lines = false
|
||||
|
||||
[{*.har,*.json,*.png.mcmeta,mcmod.info,pack.mcmeta}]
|
||||
indent_size = 2
|
||||
indent_size = 4
|
||||
ij_json_array_wrapping = split_into_lines
|
||||
ij_json_keep_blank_lines_in_code = 0
|
||||
ij_json_keep_indents_on_empty_lines = false
|
||||
@@ -688,7 +688,7 @@ ij_markdown_wrap_text_inside_blockquotes = true
|
||||
ij_toml_keep_indents_on_empty_lines = false
|
||||
|
||||
[{*.yaml,*.yml}]
|
||||
indent_size = 2
|
||||
indent_size = 4
|
||||
ij_yaml_align_values_properties = do_not_align
|
||||
ij_yaml_autoinsert_sequence_marker = true
|
||||
ij_yaml_block_mapping_on_new_line = false
|
||||
|
||||
+3
-8
@@ -18,17 +18,12 @@ variables:
|
||||
.build_java:
|
||||
#image: eclipse-temurin:17
|
||||
cache:
|
||||
key: "gradleCache_$CI_JOB_NAME_SLUG"
|
||||
key: "gradleCache"
|
||||
policy: pull-push
|
||||
paths:
|
||||
- .gradle
|
||||
- cache/
|
||||
allow_failure: true
|
||||
retry:
|
||||
max: 2
|
||||
when:
|
||||
- runner_system_failure
|
||||
- stuck_or_timeout_failure
|
||||
|
||||
|
||||
build:
|
||||
@@ -68,7 +63,7 @@ build:
|
||||
extends: .build_java
|
||||
|
||||
|
||||
.api:
|
||||
api:
|
||||
stage: api
|
||||
needs: []
|
||||
script:
|
||||
@@ -92,7 +87,7 @@ build:
|
||||
|
||||
|
||||
# generate and publish API javadocs
|
||||
.pages:
|
||||
pages:
|
||||
stage: pages
|
||||
needs: []
|
||||
script:
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
[submodule "coreSubProjects"]
|
||||
path = coreSubProjects
|
||||
url = https://gitlab.com/jeseibel/distant-horizons-core.git
|
||||
url = https://gitlab.com/jeseibel/distant-horizons-core.git
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Fabric Client & Server" type="CompoundRunConfigurationType">
|
||||
<toRun name="Fabric Client (:fabric)" type="Application" />
|
||||
<toRun name="Fabric Server (:fabric)" type="Application" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -1,7 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Forge Client & Server" type="CompoundRunConfigurationType">
|
||||
<toRun name="Forge Client (gradle)" type="GradleRunConfiguration" />
|
||||
<toRun name="Forge Server (gradle)" type="GradleRunConfiguration" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -1,24 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Forge Client (gradle)" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<ExternalSystemSettings>
|
||||
<option name="executionName" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="externalSystemIdString" value="GRADLE" />
|
||||
<option name="scriptParameters" value="" />
|
||||
<option name="taskDescriptions">
|
||||
<list />
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value="forge:runClient" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions" />
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<RunAsTest>false</RunAsTest>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -1,24 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Forge Server (gradle)" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<ExternalSystemSettings>
|
||||
<option name="executionName" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="externalSystemIdString" value="GRADLE" />
|
||||
<option name="scriptParameters" value="" />
|
||||
<option name="taskDescriptions">
|
||||
<list />
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value="forge:runServer" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions" />
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<RunAsTest>false</RunAsTest>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -1,7 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Neoforge Client & Server" type="CompoundRunConfigurationType">
|
||||
<toRun name="Neoforge Client (gradle)" type="GradleRunConfiguration" />
|
||||
<toRun name="Neoforge Server (gradle)" type="GradleRunConfiguration" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -1,24 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Neoforge Client (gradle)" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<ExternalSystemSettings>
|
||||
<option name="executionName" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="externalSystemIdString" value="GRADLE" />
|
||||
<option name="scriptParameters" value="" />
|
||||
<option name="taskDescriptions">
|
||||
<list />
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value="neoforge:runClient" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions" />
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<RunAsTest>false</RunAsTest>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
@@ -1,24 +0,0 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Neoforge Server (gradle)" type="GradleRunConfiguration" factoryName="Gradle">
|
||||
<ExternalSystemSettings>
|
||||
<option name="executionName" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="externalSystemIdString" value="GRADLE" />
|
||||
<option name="scriptParameters" value="" />
|
||||
<option name="taskDescriptions">
|
||||
<list />
|
||||
</option>
|
||||
<option name="taskNames">
|
||||
<list>
|
||||
<option value="neoforge:runServer" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="vmOptions" />
|
||||
</ExternalSystemSettings>
|
||||
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
|
||||
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||
<DebugAllEnabled>false</DebugAllEnabled>
|
||||
<RunAsTest>false</RunAsTest>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
+20
-20
@@ -27,8 +27,8 @@ def writeBuildGradlePredefine(List<String> mcVers, int mcIndex)
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("# DON'T TOUCH THIS FILE, This is handled by the build script\n");
|
||||
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < mcVers.size(); i++)
|
||||
{
|
||||
String verStr = mcVers[i].replace(".", "_");
|
||||
@@ -104,7 +104,7 @@ subprojects { p ->
|
||||
apply plugin: "com.github.johnrengelman.shadow"
|
||||
if (isMinecraftSubProject)
|
||||
apply plugin: "systems.manifold.manifold-gradle-plugin"
|
||||
|
||||
|
||||
// Apply forge's loom
|
||||
if ((findProject(":forge") && p == project(":forge")) ||
|
||||
(findProject(":neoforge") && p == project(":neoforge"))
|
||||
@@ -118,7 +118,7 @@ subprojects { p ->
|
||||
manifold {
|
||||
manifoldVersion = rootProject.manifold_version
|
||||
}
|
||||
|
||||
|
||||
|
||||
// set up custom configurations (configurations are a way to handle dependencies)
|
||||
configurations {
|
||||
@@ -191,7 +191,7 @@ subprojects { p ->
|
||||
forgeShadowMe("org.joml:joml:${rootProject.joml_version}")
|
||||
else
|
||||
implementation("org.joml:joml:${rootProject.joml_version}")
|
||||
|
||||
|
||||
// JUnit tests
|
||||
implementation("org.junit.jupiter:junit-jupiter:5.8.2")
|
||||
implementation("org.junit.jupiter:junit-jupiter-engine:5.8.2")
|
||||
@@ -201,24 +201,25 @@ subprojects { p ->
|
||||
// Note: MC 1.16 uses 8.2.1, and versions after use 8.5.12
|
||||
// We cannot relocate this library since we call some MC classes that reference it
|
||||
implementation("it.unimi.dsi:fastutil:${rootProject.fastutil_version}")
|
||||
|
||||
|
||||
|
||||
|
||||
// Compression
|
||||
forgeShadowMe("org.lz4:lz4-java:${rootProject.lz4_version}") // LZ4
|
||||
forgeShadowMe("org.tukaani:xz:${rootProject.xz_version}") // LZMA
|
||||
|
||||
// Sqlite Database
|
||||
forgeShadowMe("org.xerial:sqlite-jdbc:${rootProject.sqlite_jdbc_version}")
|
||||
|
||||
|
||||
// NightConfig (includes Toml & Json)
|
||||
forgeShadowMe("com.electronwill.night-config:toml:${rootProject.nightconfig_version}")
|
||||
forgeShadowMe("com.electronwill.night-config:json:${rootProject.nightconfig_version}")
|
||||
|
||||
// SVG (not needed atm)
|
||||
// forgeShadowMe("com.formdev:svgSalamander:${rootProject.svgSalamander_version}")
|
||||
|
||||
|
||||
// Netty
|
||||
implementation("io.netty:netty-buffer:${rootProject.netty_version}")
|
||||
// Breaks 1.16.5
|
||||
//forgeShadowMe("io.netty:netty-all:${rootProject.netty_version}")
|
||||
|
||||
// Remember, for lwjgl dependencies that arent included in Minecraft, you need to also need to add it to the ShadowJar thing
|
||||
forgeShadowMe("org.lwjgl:lwjgl-jawt:${rootProject.lwjgl_version}") {
|
||||
@@ -276,7 +277,7 @@ subprojects { p ->
|
||||
if (isMinecraftSubProject && p != project(":common")) {
|
||||
configurations.push(project.configurations.shadowCommon) // Shadow the common subproject
|
||||
relocate "com.seibel.distanthorizons.common", "loaderCommon.${p.name}.com.seibel.distanthorizons.common" // Move the loader files to a different location
|
||||
|
||||
|
||||
if (findProject(":fabricLike") && p != project(":fabricLike")) {
|
||||
configurations.push(project.configurations.shadowFabricLike) // Shadow the fabricLike subproject
|
||||
relocate "com.seibel.distanthorizons.fabriclike", "loaderCommon.${p.name}.com.seibel.distanthorizons.fabriclike" // Move the loader files to a different location
|
||||
@@ -290,11 +291,11 @@ subprojects { p ->
|
||||
|
||||
// Compression (LZ4)
|
||||
relocate "net.jpountz", "${librariesLocation}.jpountz"
|
||||
|
||||
|
||||
// Sqlite Database
|
||||
//At the moment, there is a bug in this library which doesnt allow it to be relocated
|
||||
// relocate "org.sqlite", "${librariesLocation}.sqlite"
|
||||
|
||||
|
||||
// JOML
|
||||
if (project.hasProperty("embed_joml") && embed_joml == "true")
|
||||
relocate "org.joml", "${librariesLocation}.joml"
|
||||
@@ -304,10 +305,9 @@ subprojects { p ->
|
||||
|
||||
// SVG (not needed atm)
|
||||
// relocate "com.kitfox.svg", "${librariesLocation}.kitfox.svg"
|
||||
|
||||
|
||||
// Netty
|
||||
// Don't relocate, it causes problems with using MC's FriendlyByteBufs
|
||||
// relocate "io.netty", "${librariesLocation}.netty"
|
||||
relocate "io.netty", "${librariesLocation}.netty"
|
||||
|
||||
mergeServiceFiles()
|
||||
}
|
||||
@@ -329,7 +329,7 @@ subprojects { p ->
|
||||
"META-INF/neoforge.mods.toml",
|
||||
|
||||
// The mixins for each of the loaders
|
||||
"DistantHorizons." + p.name + ".fabricLike.mixins.json"
|
||||
"DistantHorizons."+ p.name +".fabricLike.mixins.json"
|
||||
]
|
||||
def intoTargets = ["$buildDir/resources/main/"] // Location of the built resources folder
|
||||
|
||||
@@ -388,14 +388,14 @@ subprojects { p ->
|
||||
fabric_incompatibility_list : fabric_incompatibility_list,
|
||||
fabric_recommend_list : fabric_recommend_list,
|
||||
]
|
||||
|
||||
|
||||
// replace any properties in the sub-projects with the values defined here
|
||||
inputs.properties replaceProperties
|
||||
replaceProperties.put "project", project
|
||||
filesMatching(resourceTargets) {
|
||||
expand replaceProperties
|
||||
}
|
||||
|
||||
|
||||
intoTargets.each { target ->
|
||||
if (file(target).exists()) {
|
||||
copy {
|
||||
@@ -639,4 +639,4 @@ task cleanMergedJars() {
|
||||
}
|
||||
}
|
||||
// add cleanMergedJars to the end of the "clean" task
|
||||
tasks["clean"].finalizedBy(cleanMergedJars)
|
||||
tasks["clean"].finalizedBy(cleanMergedJars)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "==================== Note: All build jars will be in the folder called 'buildAllJars' ===================="
|
||||
mkdir -p buildAllJars
|
||||
rm -rf buildAllJars/*
|
||||
mkdir -p buildAllJars | true
|
||||
|
||||
# Loop trough everything in the version properties folder
|
||||
for d in versionProperties/*; do
|
||||
@@ -12,17 +11,12 @@ for d in versionProperties/*; do
|
||||
# Clean out the folders, build it, and merge it
|
||||
# (We could use "./" to run gradlew, but as it is a shell script im going to be running it with the "sh" command)
|
||||
echo "==================== Cleaning workspace to build $version ===================="
|
||||
sh gradlew clean -PmcVer=$version
|
||||
if [ $? != 0 ]; then continue; fi
|
||||
|
||||
sh gradlew clean -PmcVer=$version --no-daemon || true
|
||||
echo "====================Building $version ===================="
|
||||
sh gradlew build -PmcVer=$version
|
||||
if [ $? != 0 ]; then continue; fi
|
||||
|
||||
sh gradlew build -PmcVer=$version --no-daemon || true
|
||||
echo "==================== Merging $version ===================="
|
||||
sh gradlew mergeJars -PmcVer=$version
|
||||
if [ $? != 0 ]; then continue; fi
|
||||
|
||||
sh gradlew mergeJars -PmcVer=$version --no-daemon || true
|
||||
echo "==================== Moving jar ===================="
|
||||
mv Merged/*.jar buildAllJars/
|
||||
mv Merged/*.jar buildAllJars/ || true
|
||||
# The "| true" at the end of those are just to make sure the script continues even if a build fails
|
||||
done
|
||||
|
||||
+2
-8
@@ -1,10 +1,3 @@
|
||||
buildscript {
|
||||
configurations.configureEach {
|
||||
resolutionStrategy {
|
||||
force 'org.spongepowered:vanillagradle:0.2.1-20240507.024226-82'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// temporary fix for broken spongepowered version
|
||||
buildscript {
|
||||
@@ -42,4 +35,5 @@ publishing {
|
||||
repositories {
|
||||
// Add repositories to publish to here.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-168
@@ -1,30 +1,18 @@
|
||||
package com.seibel.distanthorizons.common;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.*;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiAfterDhInitEvent;
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiBeforeDhInitEvent;
|
||||
import com.seibel.distanthorizons.common.wrappers.DependencySetup;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftDedicatedServerWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.config.ConfigBase;
|
||||
import com.seibel.distanthorizons.core.config.eventHandlers.presets.ThreadPresetConfigEventHandler;
|
||||
import com.seibel.distanthorizons.core.config.types.AbstractConfigType;
|
||||
import com.seibel.distanthorizons.core.config.types.ConfigEntry;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.jar.ModJarInfo;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.network.messages.MessageRegistry;
|
||||
import com.seibel.distanthorizons.core.network.messages.base.CodecCrashMessage;
|
||||
import com.seibel.distanthorizons.core.util.objects.Pair;
|
||||
import com.seibel.distanthorizons.core.world.DhServerWorld;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModAccessor;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||
@@ -35,25 +23,9 @@ import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.mojang.brigadier.arguments.DoubleArgumentType.doubleArg;
|
||||
import static com.mojang.brigadier.arguments.IntegerArgumentType.integer;
|
||||
import static com.seibel.distanthorizons.core.network.messages.MessageRegistry.DEBUG_ENABLE_CODEC_CRASH_MESSAGE;
|
||||
import static net.minecraft.commands.Commands.argument;
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
#if MC_VER >= MC_1_19_2
|
||||
import net.minecraft.network.chat.Component;
|
||||
#else // < 1.19.2
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Base for all mod loader initializers
|
||||
* and handles most setup.
|
||||
@@ -95,7 +67,7 @@ public abstract class AbstractModInitializer
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
|
||||
|
||||
this.startup();
|
||||
this.printModInfo();
|
||||
this.printModInfo(true);
|
||||
|
||||
this.createClientProxy().registerEvents();
|
||||
this.createServerProxy(false).registerEvents();
|
||||
@@ -119,7 +91,7 @@ public abstract class AbstractModInitializer
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
|
||||
|
||||
this.startup();
|
||||
this.printModInfo();
|
||||
this.printModInfo(false);
|
||||
|
||||
// This prevents returning uninitialized Config values,
|
||||
// resulting from a circular reference mid-initialization in a static class
|
||||
@@ -128,8 +100,6 @@ public abstract class AbstractModInitializer
|
||||
|
||||
this.createServerProxy(true).registerEvents();
|
||||
|
||||
this.initializeModCompat();
|
||||
|
||||
LOGGER.info(ModInfo.READABLE_NAME + " Initialized");
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiAfterDhInitEvent.class, null);
|
||||
|
||||
@@ -160,14 +130,17 @@ public abstract class AbstractModInitializer
|
||||
this.createInitialBindings();
|
||||
}
|
||||
|
||||
private void printModInfo()
|
||||
private void printModInfo(boolean printGitInfo)
|
||||
{
|
||||
LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
|
||||
|
||||
// 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);
|
||||
if (printGitInfo)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
protected <T extends IModAccessor> void tryCreateModCompatAccessor(String modId, Class<? super T> accessorClass, Supplier<T> accessorConstructor)
|
||||
@@ -193,136 +166,7 @@ public abstract class AbstractModInitializer
|
||||
LOGGER.info("Mod Post-Initialized");
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
private void initCommands()
|
||||
{
|
||||
LiteralArgumentBuilder<CommandSourceStack> builder = literal("dhconfig")
|
||||
.requires(source -> source.hasPermission(4));
|
||||
|
||||
for (AbstractConfigType<?, ?> type : ConfigBase.INSTANCE.entries)
|
||||
{
|
||||
if (!(type instanceof ConfigEntry))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//noinspection PatternVariableCanBeUsed
|
||||
ConfigEntry configEntry = (ConfigEntry) type;
|
||||
if (configEntry.getServersideShortName() == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Function<
|
||||
Function<CommandContext<CommandSourceStack>, Object>,
|
||||
Command<CommandSourceStack>
|
||||
> makeConfigUpdater = getter -> c -> {
|
||||
Object value = getter.apply(c);
|
||||
|
||||
c.getSource().sendSuccess(
|
||||
#if MC_VER >= MC_1_20_1
|
||||
() -> Component.literal("Changed the value of "+configEntry.getServersideShortName()+" to "+value),
|
||||
#elif MC_VER >= MC_1_19_2
|
||||
Component.literal("Changed the value of "+configEntry.getServersideShortName()+" to "+value),
|
||||
#else
|
||||
new TranslatableComponent("Changed the value of "+configEntry.getServersideShortName()+" to "+value),
|
||||
#endif
|
||||
true);
|
||||
configEntry.set(value);
|
||||
return 1;
|
||||
};
|
||||
|
||||
LiteralArgumentBuilder<CommandSourceStack> subcommand = literal(configEntry.getServersideShortName())
|
||||
.executes(c -> {
|
||||
#if MC_VER >= MC_1_20_1
|
||||
c.getSource().sendSuccess(() -> Component.literal("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
|
||||
#elif MC_VER >= MC_1_19_2
|
||||
c.getSource().sendSuccess(Component.literal("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
|
||||
#else // < 1.19.2
|
||||
c.getSource().sendSuccess(new TranslatableComponent("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
|
||||
#endif
|
||||
return 1;
|
||||
});
|
||||
|
||||
if (Enum.class.isAssignableFrom(configEntry.getType()))
|
||||
{
|
||||
for (Object choice : configEntry.getType().getEnumConstants())
|
||||
{
|
||||
subcommand.then(
|
||||
literal(choice.toString())
|
||||
.executes(makeConfigUpdater.apply(c -> choice))
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
boolean setterAdded = false;
|
||||
|
||||
for (java.util.Map.Entry<Class<?>, Pair<Supplier<ArgumentType<?>>, BiFunction<CommandContext<?>, String, ?>>> pair : new HashMap<
|
||||
Class<?>,
|
||||
Pair<
|
||||
Supplier<ArgumentType<?>>,
|
||||
BiFunction<CommandContext<?>, String, ?>>
|
||||
>() {{
|
||||
this.put(Integer.class, new Pair<>(() -> integer((int) configEntry.getMin(), (int) configEntry.getMax()), IntegerArgumentType::getInteger));
|
||||
this.put(Double.class, new Pair<>(() -> doubleArg((double) configEntry.getMin(), (double) configEntry.getMax()), DoubleArgumentType::getDouble));
|
||||
this.put(Boolean.class, new Pair<>(BoolArgumentType::bool, BoolArgumentType::getBool));
|
||||
this.put(String.class, new Pair<>(StringArgumentType::string, StringArgumentType::getString));
|
||||
}}.entrySet())
|
||||
{
|
||||
if (!pair.getKey().isAssignableFrom(configEntry.getType()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
subcommand.then(argument("value", pair.getValue().first.get())
|
||||
.executes(makeConfigUpdater.apply(c -> pair.getValue().second.apply(c, "value"))));
|
||||
|
||||
setterAdded = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!setterAdded)
|
||||
{
|
||||
throw new RuntimeException("Config type of "+type.getName()+" is not supported: "+configEntry.getType().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
builder.then(subcommand);
|
||||
}
|
||||
|
||||
this.commandDispatcher.register(builder);
|
||||
|
||||
if (DEBUG_ENABLE_CODEC_CRASH_MESSAGE)
|
||||
{
|
||||
LiteralArgumentBuilder<CommandSourceStack> dhcrash = literal("dhcrash")
|
||||
.requires(source -> source.hasPermission(4))
|
||||
.then(literal("encode")
|
||||
.executes(c -> {
|
||||
assert SharedApi.getIDhServerWorld() != null;
|
||||
((DhServerWorld) SharedApi.getIDhServerWorld()).remotePlayerConnectionHandler
|
||||
#if MC_VER >= MC_1_19_2
|
||||
.getConnectedPlayer(ServerPlayerWrapper.getWrapper(Objects.requireNonNull(c.getSource().getPlayer())))
|
||||
#else
|
||||
.getConnectedPlayer(ServerPlayerWrapper.getWrapper(Objects.requireNonNull(c.getSource().getPlayerOrException())))
|
||||
#endif
|
||||
.session.sendMessage(new CodecCrashMessage(CodecCrashMessage.ECrashPhase.ENCODE));
|
||||
return 1;
|
||||
}))
|
||||
.then(literal("decode")
|
||||
.executes(c -> {
|
||||
assert SharedApi.getIDhServerWorld() != null;
|
||||
((DhServerWorld) SharedApi.getIDhServerWorld()).remotePlayerConnectionHandler
|
||||
#if MC_VER >= MC_1_19_2
|
||||
.getConnectedPlayer(ServerPlayerWrapper.getWrapper(Objects.requireNonNull(c.getSource().getPlayer())))
|
||||
#else
|
||||
.getConnectedPlayer(ServerPlayerWrapper.getWrapper(Objects.requireNonNull(c.getSource().getPlayerOrException())))
|
||||
#endif
|
||||
.session.sendMessage(new CodecCrashMessage(CodecCrashMessage.ECrashPhase.DECODE));
|
||||
return 1;
|
||||
}));
|
||||
this.commandDispatcher.register(dhcrash);
|
||||
}
|
||||
}
|
||||
private void initCommands() { /* currently unimplemented */ }
|
||||
|
||||
|
||||
|
||||
@@ -335,4 +179,4 @@ public abstract class AbstractModInitializer
|
||||
void registerEvents();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-114
@@ -1,114 +0,0 @@
|
||||
package com.seibel.distanthorizons.common;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.logging.ConfigBasedLogger;
|
||||
import com.seibel.distanthorizons.core.network.event.internal.IncompatibleMessageEvent;
|
||||
import com.seibel.distanthorizons.core.network.event.internal.ProtocolErrorEvent;
|
||||
import com.seibel.distanthorizons.core.network.messages.MessageRegistry;
|
||||
import com.seibel.distanthorizons.core.network.messages.NetworkMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.base.CloseReasonMessage;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AbstractPluginPacketSender implements IPluginPacketSender
|
||||
{
|
||||
private static final ConfigBasedLogger LOGGER = new ConfigBasedLogger(LogManager.getLogger(),
|
||||
() -> Config.Client.Advanced.Logging.logNetworkEvent.get());
|
||||
|
||||
#if MC_VER >= MC_1_21_1
|
||||
public static final ResourceLocation WRAPPER_PACKET_RESOURCE = ResourceLocation.fromNamespaceAndPath(ModInfo.RESOURCE_NAMESPACE, ModInfo.WRAPPER_PACKET_PATH);
|
||||
#else
|
||||
public static final ResourceLocation WRAPPER_PACKET_RESOURCE = new ResourceLocation(ModInfo.RESOURCE_NAMESPACE, ModInfo.WRAPPER_PACKET_PATH);
|
||||
#endif
|
||||
|
||||
|
||||
@Override
|
||||
public final void sendPluginPacketServer(IServerPlayerWrapper serverPlayer, NetworkMessage message)
|
||||
{
|
||||
this.sendPluginPacketServer((ServerPlayer) serverPlayer.getWrappedMcObject(), message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void sendPluginPacketClient(NetworkMessage message);
|
||||
public abstract void sendPluginPacketServer(ServerPlayer serverPlayer, NetworkMessage message);
|
||||
|
||||
@Nullable
|
||||
public static NetworkMessage decodeMessage(FriendlyByteBuf in)
|
||||
{
|
||||
NetworkMessage message = null;
|
||||
|
||||
try
|
||||
{
|
||||
in.markReaderIndex();
|
||||
|
||||
int protocolVersion = in.readShort();
|
||||
if (protocolVersion != ModInfo.PROTOCOL_VERSION)
|
||||
{
|
||||
return new IncompatibleMessageEvent(protocolVersion);
|
||||
}
|
||||
|
||||
message = MessageRegistry.INSTANCE.createMessage(in.readUnsignedShort());
|
||||
message.decode(in);
|
||||
|
||||
if (in.isReadable())
|
||||
{
|
||||
throw new IOException("Buffer has not been fully read");
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
in.resetReaderIndex();
|
||||
|
||||
LOGGER.error("Failed to decode message", e);
|
||||
LOGGER.error("Buffer: {}", in);
|
||||
LOGGER.error("Buffer contents: [{}]", ByteBufUtil.hexDump(in));
|
||||
|
||||
return new ProtocolErrorEvent(e, message, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Prevent connection crashing if not entire buffer has been read
|
||||
in.readerIndex(in.writerIndex());
|
||||
}
|
||||
}
|
||||
|
||||
public static void encodeMessage(FriendlyByteBuf out, NetworkMessage message)
|
||||
{
|
||||
// This is intentionally unhandled, because errors related to this are unlikely to appear in wild
|
||||
Objects.requireNonNull(message);
|
||||
out.writeShort(ModInfo.PROTOCOL_VERSION);
|
||||
|
||||
try
|
||||
{
|
||||
out.markWriterIndex();
|
||||
out.writeShort(MessageRegistry.INSTANCE.getMessageId(message));
|
||||
message.encode(out);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.error("Failed to encode message", e);
|
||||
LOGGER.error("Message: {}", message);
|
||||
|
||||
message.getSession().tryHandleMessage(new ProtocolErrorEvent(e, message, false));
|
||||
|
||||
// Encode close reason message instead
|
||||
out.resetWriterIndex();
|
||||
message = new CloseReasonMessage("Internal error on other side");
|
||||
out.writeShort(MessageRegistry.INSTANCE.getMessageId(message));
|
||||
message.encode(out);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.seibel.distanthorizons.common;
|
||||
|
||||
#if MC_VER >= MC_1_20_6
|
||||
|
||||
import com.seibel.distanthorizons.core.network.messages.NetworkMessage;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public record CommonPacketPayload(
|
||||
@Nullable NetworkMessage message
|
||||
) implements CustomPacketPayload
|
||||
{
|
||||
public static final Type<CommonPacketPayload> TYPE = new Type<>(AbstractPluginPacketSender.WRAPPER_PACKET_RESOURCE);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Type<? extends CustomPacketPayload> type()
|
||||
{
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
|
||||
public static class Codec implements StreamCodec<FriendlyByteBuf, CommonPacketPayload>
|
||||
{
|
||||
@NotNull
|
||||
@Override
|
||||
public CommonPacketPayload decode(@NotNull FriendlyByteBuf in)
|
||||
{
|
||||
return new CommonPacketPayload(AbstractPluginPacketSender.decodeMessage(in));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(@NotNull FriendlyByteBuf out, CommonPacketPayload payload)
|
||||
{
|
||||
AbstractPluginPacketSender.encodeMessage(out, payload.message());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+14
-4
@@ -179,9 +179,19 @@ public class WrapperFactory implements IWrapperFactory
|
||||
|
||||
|
||||
// level wrapper
|
||||
ILevelWrapper levelWrapper = level.isClientSide()
|
||||
? ClientLevelWrapper.getWrapper((ClientLevel)level)
|
||||
: ServerLevelWrapper.getWrapper((ServerLevel)level);
|
||||
ILevelWrapper levelWrapper;
|
||||
if (level instanceof ServerLevel)
|
||||
{
|
||||
levelWrapper = ServerLevelWrapper.getWrapper((ServerLevel)level);
|
||||
}
|
||||
else if (level instanceof ClientLevel)
|
||||
{
|
||||
levelWrapper = ClientLevelWrapper.getWrapper((ClientLevel)level);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
||||
}
|
||||
|
||||
|
||||
return new ChunkWrapper(chunk, lightSource, levelWrapper);
|
||||
@@ -205,7 +215,7 @@ public class WrapperFactory implements IWrapperFactory
|
||||
expectedClassNames = new String[]
|
||||
{
|
||||
ChunkAccess.class.getName(),
|
||||
"[ServerLevel] or [ClientLevel]" // Classes are not referenced by names to avoid exception when one of them is missing
|
||||
ServerLevel.class.getName() + "] or [" + ClientLevel.class.getName()
|
||||
};
|
||||
//#endif
|
||||
|
||||
|
||||
+5
-2
@@ -54,6 +54,7 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.EmptyBlockGetter;
|
||||
#else
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
@@ -541,7 +542,9 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
{
|
||||
|
||||
#if MC_VER > MC_1_17_1
|
||||
Level level = (Level)Objects.requireNonNull(levelWrapper.getWrappedMcObject());
|
||||
// use the given level if possible, otherwise try using the currently loaded one
|
||||
Level level = (levelWrapper != null ? (Level) levelWrapper.getWrappedMcObject() : null);
|
||||
level = (level == null ? Minecraft.getInstance().level : level);
|
||||
#endif
|
||||
|
||||
Block block;
|
||||
@@ -756,4 +759,4 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+3
-7
@@ -22,12 +22,9 @@ package com.seibel.distanthorizons.common.wrappers.chunk;
|
||||
import com.seibel.distanthorizons.common.wrappers.block.BiomeWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.block.BlockStateWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.worldGeneration.mimicObject.DhLitWorldGenRegion;
|
||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.util.LodUtil;
|
||||
import com.seibel.distanthorizons.core.world.EWorldEnvironment;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.ChunkLightStorage;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
@@ -143,8 +140,7 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
|
||||
// FIXME +1 is to handle the fact that LodDataBuilder adds +1 to all block lighting calculations, also done in the relative position validator
|
||||
|
||||
if (SharedApi.getEnvironment() != EWorldEnvironment.Server_Only)
|
||||
chunksNeedingClientLightUpdating.add(this);
|
||||
chunksNeedingClientLightUpdating.add(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -352,7 +348,7 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
if (this.chunk instanceof LevelChunk)
|
||||
{
|
||||
LevelChunk levelChunk = (LevelChunk) this.chunk;
|
||||
if (levelChunk.getLevel().isClientSide())
|
||||
if (levelChunk.getLevel() instanceof ClientLevel)
|
||||
{
|
||||
// connected to a server
|
||||
return this.isMcClientLightingCorrect;
|
||||
@@ -609,4 +605,4 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
// return this.blockBiomeHashCode;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+17
-30
@@ -1,20 +1,21 @@
|
||||
package com.seibel.distanthorizons.common.wrappers.level;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.level.IServerKeyedClientLevel;
|
||||
import com.seibel.distanthorizons.core.level.IKeyedClientLevelManager;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class KeyedClientLevelManager implements IKeyedClientLevelManager
|
||||
{
|
||||
public static final KeyedClientLevelManager INSTANCE = new KeyedClientLevelManager();
|
||||
|
||||
/** This is set and managed by the ClientApi for servers with support for DH. */
|
||||
@Nullable
|
||||
private IServerKeyedClientLevel serverKeyedLevel = null;
|
||||
private boolean enabled = false;
|
||||
|
||||
private IServerKeyedClientLevel overrideWrapper = null;
|
||||
private boolean useOverrideWrapper = false;
|
||||
|
||||
|
||||
//=============//
|
||||
@@ -29,39 +30,25 @@ public class KeyedClientLevelManager implements IKeyedClientLevelManager
|
||||
// level override logic //
|
||||
//======================//
|
||||
|
||||
@Override
|
||||
public void setServerKeyedLevel(IServerKeyedClientLevel clientLevel) { this.overrideWrapper = clientLevel; }
|
||||
@Override
|
||||
public IServerKeyedClientLevel getOverrideWrapper() { return this.overrideWrapper; }
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IServerKeyedClientLevel getServerKeyedLevel()
|
||||
public IServerKeyedClientLevel getServerKeyedLevel(ILevelWrapper level, String serverLevelKey)
|
||||
{
|
||||
return this.serverKeyedLevel;
|
||||
Objects.requireNonNull(level);
|
||||
Objects.requireNonNull(serverLevelKey);
|
||||
return new ServerKeyedClientLevel((ClientLevel) level.getWrappedMcObject(), serverLevelKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IServerKeyedClientLevel setServerKeyedLevel(IClientLevelWrapper clientLevel, String levelKey)
|
||||
{
|
||||
IServerKeyedClientLevel keyedLevel = new ServerKeyedClientLevel((ClientLevel) clientLevel.getWrappedMcObject(), levelKey);
|
||||
this.serverKeyedLevel = keyedLevel;
|
||||
this.enabled = true;
|
||||
return keyedLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearServerKeyedLevel()
|
||||
{
|
||||
this.serverKeyedLevel = null;
|
||||
}
|
||||
|
||||
public void setUseOverrideWrapper(boolean useOverrideWrapper) { this.useOverrideWrapper = useOverrideWrapper; }
|
||||
@Override
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return this.enabled;
|
||||
}
|
||||
public boolean getUseOverrideWrapper() { return this.useOverrideWrapper; }
|
||||
|
||||
|
||||
@Override
|
||||
public void disable()
|
||||
{
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-8
@@ -18,11 +18,4 @@ public class ServerKeyedClientLevel extends ClientLevelWrapper implements IServe
|
||||
@Override
|
||||
public String getServerLevelKey() { return this.serverLevelKey; }
|
||||
|
||||
|
||||
@Override
|
||||
public String getDimensionName()
|
||||
{
|
||||
return this.getServerLevelKey();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+3
-22
@@ -44,7 +44,6 @@ import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
|
||||
import net.minecraft.CrashReport;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -54,7 +53,6 @@ import net.minecraft.network.chat.TextComponent;
|
||||
#endif
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -224,20 +222,12 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
|
||||
@Override
|
||||
public IClientLevelWrapper getWrappedClientLevel()
|
||||
{
|
||||
return this.getWrappedClientLevel(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IClientLevelWrapper getWrappedClientLevel(boolean bypassMultiverse)
|
||||
{
|
||||
ClientLevel level = MINECRAFT.level;
|
||||
if (level == null)
|
||||
if (MINECRAFT.level == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return ClientLevelWrapper.getWrapper(level, bypassMultiverse);
|
||||
return ClientLevelWrapper.getWrapperIgnoringOverride(MINECRAFT.level);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -276,10 +266,7 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
|
||||
public void sendChatMessage(String string)
|
||||
{
|
||||
LocalPlayer player = this.getPlayer();
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (player == null) return;
|
||||
#if MC_VER < MC_1_19_2
|
||||
player.sendMessage(new TextComponent(string), getPlayer().getUUID());
|
||||
#else
|
||||
@@ -319,10 +306,4 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
|
||||
@Override
|
||||
public void executeOnRenderThread(Runnable runnable) { MINECRAFT.execute(runnable); }
|
||||
|
||||
@Override
|
||||
public boolean isWorldInitialized()
|
||||
{
|
||||
throw new NotImplementedException("TODO");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-7
@@ -28,10 +28,4 @@ public class MinecraftDedicatedServerWrapper implements IMinecraftSharedWrapper
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorldInitialized()
|
||||
{
|
||||
return this.dedicatedServer.getWorldData().overworldData().isInitialized();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package com.seibel.distanthorizons.common.wrappers.misc;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IMixinServerPlayer
|
||||
{
|
||||
@Nullable
|
||||
ServerLevel distantHorizons$getDimensionChangeDestination();
|
||||
|
||||
}
|
||||
+16
-82
@@ -1,120 +1,54 @@
|
||||
package com.seibel.distanthorizons.common.wrappers.misc;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* This wrapper transparently ensures that underlying {@link ServerPlayer} is always valid,
|
||||
* unless the player has disconnected.
|
||||
*/
|
||||
public class ServerPlayerWrapper implements IServerPlayerWrapper
|
||||
{
|
||||
private static final ConcurrentMap<ServerGamePacketListenerImpl, ServerPlayerWrapper> serverPlayerWrapperMap = new MapMaker().weakKeys().weakValues().makeMap();
|
||||
private static final ConcurrentMap<ServerPlayer, ServerPlayerWrapper>
|
||||
serverPlayerWrapperMap = new MapMaker().weakKeys().makeMap();
|
||||
|
||||
private final ServerGamePacketListenerImpl connection;
|
||||
private ServerPlayer serverPlayer()
|
||||
{
|
||||
return this.connection.player;
|
||||
}
|
||||
private final ServerPlayer serverPlayer;
|
||||
|
||||
public static ServerPlayerWrapper getWrapper(ServerPlayer serverPlayer)
|
||||
{
|
||||
return serverPlayerWrapperMap.computeIfAbsent(serverPlayer.connection, ignored -> new ServerPlayerWrapper(serverPlayer.connection));
|
||||
return serverPlayerWrapperMap.computeIfAbsent(serverPlayer, ServerPlayerWrapper::new);
|
||||
}
|
||||
|
||||
private ServerPlayerWrapper(ServerGamePacketListenerImpl connection)
|
||||
private ServerPlayerWrapper(ServerPlayer serverPlayer)
|
||||
{
|
||||
this.connection = connection;
|
||||
this.serverPlayer = serverPlayer;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
public UUID getUUID()
|
||||
{
|
||||
return this.serverPlayer().getName().getString();
|
||||
return serverPlayer.getUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IServerLevelWrapper getLevel()
|
||||
{
|
||||
ServerLevel level = ((IMixinServerPlayer) this.serverPlayer()).distantHorizons$getDimensionChangeDestination();
|
||||
if (level == null)
|
||||
{
|
||||
#if MC_VER < MC_1_20_1
|
||||
level = this.serverPlayer().getLevel();
|
||||
#else
|
||||
level = this.serverPlayer().serverLevel();
|
||||
#endif
|
||||
}
|
||||
|
||||
return ServerLevelWrapper.getWrapper(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3d getPosition()
|
||||
{
|
||||
Vec3 position = this.serverPlayer().position();
|
||||
return new Vec3d(position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewDistance()
|
||||
{
|
||||
return this.serverPlayer().server.getPlayerList().getViewDistance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteAddress()
|
||||
{
|
||||
#if MC_VER >= MC_1_19_4
|
||||
return this.serverPlayer().connection.getRemoteAddress();
|
||||
#else // < 1.19.4
|
||||
return this.serverPlayer().connection.connection.getRemoteAddress();
|
||||
#if MC_VER < MC_1_20_1
|
||||
return ServerLevelWrapper.getWrapper(this.serverPlayer.getLevel());
|
||||
#else
|
||||
return ServerLevelWrapper.getWrapper(this.serverPlayer.serverLevel());
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getWrappedMcObject()
|
||||
{
|
||||
return this.serverPlayer();
|
||||
return serverPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Wrapped{" + this.serverPlayer() + "}";
|
||||
return "Wrapped{" + serverPlayer.toString() + "}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof ServerPlayerWrapper))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ServerPlayerWrapper that = (ServerPlayerWrapper) o;
|
||||
return Objects.equal(this.connection, that.connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hashCode(this.connection);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+15
-29
@@ -9,7 +9,6 @@ import com.seibel.distanthorizons.common.wrappers.block.ClientBlockStateColorCac
|
||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.level.*;
|
||||
import com.seibel.distanthorizons.core.level.IServerKeyedClientLevel;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
@@ -70,31 +69,23 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
// wrapper logic //
|
||||
//===============//
|
||||
|
||||
public static IClientLevelWrapper getWrapper(@NotNull ClientLevel level)
|
||||
{
|
||||
return getWrapper(level, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IClientLevelWrapper getWrapper(@Nullable ClientLevel level, boolean bypassLevelKeyManager)
|
||||
public static IClientLevelWrapper getWrapper(@Nullable ClientLevel level)
|
||||
{
|
||||
if (!bypassLevelKeyManager)
|
||||
if (level == null)
|
||||
{
|
||||
if (level == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// used if the client is connected to a server that defines the currently loaded level
|
||||
IServerKeyedClientLevel overrideLevel = KEYED_CLIENT_LEVEL_MANAGER.getServerKeyedLevel();
|
||||
if (overrideLevel != null)
|
||||
{
|
||||
return overrideLevel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return LEVEL_WRAPPER_BY_CLIENT_LEVEL.computeIfAbsent(level, ClientLevelWrapper::new);
|
||||
// used if the client is connected to a server that defines the currently loaded level
|
||||
if (KEYED_CLIENT_LEVEL_MANAGER.getUseOverrideWrapper())
|
||||
{
|
||||
return KEYED_CLIENT_LEVEL_MANAGER.getOverrideWrapper();
|
||||
}
|
||||
|
||||
return getWrapperIgnoringOverride(level);
|
||||
}
|
||||
public static IClientLevelWrapper getWrapperIgnoringOverride(@NotNull ClientLevel level) { return LEVEL_WRAPPER_BY_CLIENT_LEVEL.computeIfAbsent(level, ClientLevelWrapper::new); }
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@@ -127,6 +118,8 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//====================//
|
||||
// base level methods //
|
||||
//====================//
|
||||
@@ -186,13 +179,6 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
|
||||
@Override
|
||||
public IDimensionTypeWrapper getDimensionType() { return DimensionTypeWrapper.getDimensionTypeWrapper(this.level.dimensionType()); }
|
||||
|
||||
|
||||
@Override
|
||||
public String getDimensionName()
|
||||
{
|
||||
return this.level.dimension().location().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EDhApiLevelType getLevelType() { return EDhApiLevelType.CLIENT_LEVEL; }
|
||||
@@ -302,7 +288,7 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
return "Wrapped{null}";
|
||||
}
|
||||
|
||||
return "Wrapped{" + this.level.toString() + "@" + this.getDimensionName() + "}";
|
||||
return "Wrapped{" + this.level.toString() + "@" + this.getDimensionType().getDimensionName() + "}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+7
-21
@@ -44,9 +44,7 @@ public class DimensionTypeWrapper implements IDimensionTypeWrapper
|
||||
{
|
||||
//first we check if the biome has already been wrapped
|
||||
if (dimensionTypeWrapperMap.containsKey(dimensionType) && dimensionTypeWrapperMap.get(dimensionType) != null)
|
||||
{
|
||||
return dimensionTypeWrapperMap.get(dimensionType);
|
||||
}
|
||||
|
||||
|
||||
//if it hasn't been created yet, we create it and save it in the map
|
||||
@@ -63,26 +61,22 @@ public class DimensionTypeWrapper implements IDimensionTypeWrapper
|
||||
}
|
||||
|
||||
|
||||
private String getDimensionName()
|
||||
@Override
|
||||
public String getDimensionName()
|
||||
{
|
||||
#if MC_VER >= MC_1_17_1
|
||||
return this.dimensionType.effectsLocation().getPath();
|
||||
#else // < 1.17.1
|
||||
// effectsLocation() is marked as client only, so using the backing field directly
|
||||
return dimensionType.effectsLocation.getPath();
|
||||
#endif
|
||||
return dimensionType.effectsLocation().getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCeiling()
|
||||
{
|
||||
return this.dimensionType.hasCeiling();
|
||||
return dimensionType.hasCeiling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkyLight()
|
||||
{
|
||||
return this.dimensionType.hasSkyLight();
|
||||
return dimensionType.hasSkyLight();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,15 +85,7 @@ public class DimensionTypeWrapper implements IDimensionTypeWrapper
|
||||
return this.dimensionType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTeleportationScale(IDimensionTypeWrapper to)
|
||||
{
|
||||
return DimensionType.getTeleportationScale(this.dimensionType, (DimensionType) to.getWrappedMcObject());
|
||||
}
|
||||
|
||||
// there's definitely a better way of doing this, but it should work well enough for now
|
||||
@Override
|
||||
public boolean isTheEnd() { return this.getDimensionName().equalsIgnoreCase("the_end"); }
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
@@ -116,4 +102,4 @@ public class DimensionTypeWrapper implements IDimensionTypeWrapper
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+16
-28
@@ -83,19 +83,13 @@ public class ServerLevelWrapper implements IServerLevelWrapper
|
||||
@Override
|
||||
public File getSaveFolder()
|
||||
{
|
||||
return this.level.getChunkSource().getDataStorage().dataFolder;
|
||||
return level.getChunkSource().getDataStorage().dataFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionTypeWrapper getDimensionType()
|
||||
{
|
||||
return DimensionTypeWrapper.getDimensionTypeWrapper(this.level.dimensionType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDimensionName()
|
||||
{
|
||||
return this.level.dimension().location().toString();
|
||||
return DimensionTypeWrapper.getDimensionTypeWrapper(level.dimensionType());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -103,25 +97,25 @@ public class ServerLevelWrapper implements IServerLevelWrapper
|
||||
|
||||
public ServerLevel getLevel()
|
||||
{
|
||||
return this.level;
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCeiling()
|
||||
{
|
||||
return this.level.dimensionType().hasCeiling();
|
||||
return level.dimensionType().hasCeiling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkyLight()
|
||||
{
|
||||
return this.level.dimensionType().hasSkyLight();
|
||||
return level.dimensionType().hasSkyLight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight()
|
||||
{
|
||||
return this.level.getHeight();
|
||||
return level.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,43 +124,37 @@ public class ServerLevelWrapper implements IServerLevelWrapper
|
||||
#if MC_VER < MC_1_17_1
|
||||
return 0;
|
||||
#else
|
||||
return this.level.getMinBuildHeight();
|
||||
return level.getMinBuildHeight();
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChunkWrapper tryGetChunk(DhChunkPos pos)
|
||||
{
|
||||
if (!this.level.hasChunk(pos.getX(), pos.getZ()))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ChunkAccess chunk = this.level.getChunk(pos.getX(), pos.getZ(), ChunkStatus.FULL, false);
|
||||
if (chunk == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ChunkWrapper(chunk, this.level, this);
|
||||
if (!level.hasChunk(pos.getX(), pos.getZ())) return null;
|
||||
ChunkAccess chunk = level.getChunk(pos.getX(), pos.getZ(), ChunkStatus.FULL, false);
|
||||
if (chunk == null) return null;
|
||||
return new ChunkWrapper(chunk, level, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChunkLoaded(int chunkX, int chunkZ)
|
||||
{
|
||||
// world.hasChunk(chunkX, chunkZ); THIS DOES NOT WORK FOR CLIENT LEVEL CAUSE MOJANG ALWAYS RETURN TRUE FOR THAT!
|
||||
ChunkSource source = this.level.getChunkSource();
|
||||
ChunkSource source = level.getChunkSource();
|
||||
return source.hasChunk(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockStateWrapper getBlockState(DhBlockPos pos)
|
||||
{
|
||||
return BlockStateWrapper.fromBlockState(this.level.getBlockState(McObjectConverter.Convert(pos)), this);
|
||||
return BlockStateWrapper.fromBlockState(level.getBlockState(McObjectConverter.Convert(pos)), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBiomeWrapper getBiome(DhBlockPos pos)
|
||||
{
|
||||
return BiomeWrapper.getBiomeWrapper(this.level.getBiome(McObjectConverter.Convert(pos)), this);
|
||||
return BiomeWrapper.getBiomeWrapper(level.getBiome(McObjectConverter.Convert(pos)), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -197,6 +185,6 @@ public class ServerLevelWrapper implements IServerLevelWrapper
|
||||
//================//
|
||||
|
||||
@Override
|
||||
public String toString() { return "Wrapped{" + this.level.toString() + "@" + this.getDimensionName() + "}"; }
|
||||
public String toString() { return "Wrapped{" + this.level.toString() + "@" + this.getDimensionType().getDimensionName() + "}"; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ public class ChunkLoader
|
||||
ChunkPos actualPos = new ChunkPos(tagLevel.getInt("xPos"), tagLevel.getInt("zPos"));
|
||||
if (!Objects.equals(chunkPos, actualPos))
|
||||
{
|
||||
#if MC_VER >= MC_1_18_2
|
||||
#if MC_VER > MC_1_17_1
|
||||
if (actualPos.equals(ChunkPos.ZERO))
|
||||
#else
|
||||
if (actualPos.equals(ChunkPos.INVALID_CHUNK_POS))
|
||||
|
||||
@@ -47,7 +47,4 @@ accessible field net/minecraft/client/renderer/texture/TextureAtlasSprite frames
|
||||
accessible field net/minecraft/client/renderer/texture/TextureAtlasSprite framesY [I
|
||||
accessible field net/minecraft/client/renderer/texture/TextureAtlasSprite mainImage [Lcom/mojang/blaze3d/platform/NativeImage;
|
||||
|
||||
# DimensionTypeWrapper workaround
|
||||
accessible field net/minecraft/world/level/dimension/DimensionType effectsLocation Lnet/minecraft/resources/ResourceLocation;
|
||||
|
||||
extendable class com/mojang/math/Matrix4f
|
||||
|
||||
+1
-1
Submodule coreSubProjects updated: 7cd1a37914...57c5b2d5fc
+3
-14
@@ -5,25 +5,19 @@ plugins {
|
||||
loom {
|
||||
accessWidenerPath = project(":common").file("src/main/resources/${accessWidenerVersion}.distanthorizons.accesswidener")
|
||||
|
||||
// Custom logging
|
||||
log4jConfigs.from(file("log4j-dev.xml"))
|
||||
|
||||
// "runs" isn't required, but when we do need it then it can be useful
|
||||
runs {
|
||||
client {
|
||||
client()
|
||||
setConfigName("Fabric Client")
|
||||
ideConfigGenerated(true)
|
||||
runDir("../run/client")
|
||||
vmArgs("-Dio.netty.leakDetection.level=advanced")
|
||||
programArgs("--username", "Dev")
|
||||
runDir("../run")
|
||||
}
|
||||
server {
|
||||
server()
|
||||
setConfigName("Fabric Server")
|
||||
ideConfigGenerated(true)
|
||||
runDir("../run/server")
|
||||
vmArgs("-Dio.netty.leakDetection.level=advanced")
|
||||
runDir("../run")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,11 +69,6 @@ dependencies {
|
||||
addModJar(fabricApi.module("fabric-events-interaction-v0", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-rendering-v1", rootProject.fabric_api_version)) // TODO: Remove this as it is only needed in 1 line (FabricClientProxy)
|
||||
addModJar(fabricApi.module("fabric-networking-api-v1", rootProject.fabric_api_version))
|
||||
addModJar(fabricApi.module("fabric-entity-events-v1", rootProject.fabric_api_version))
|
||||
if (minecraft_version >= "1.19.2")
|
||||
addModJar(fabricApi.module("fabric-command-api-v2", rootProject.fabric_api_version))
|
||||
else // < 1.19.2
|
||||
addModJar(fabricApi.module("fabric-command-api-v1", rootProject.fabric_api_version))
|
||||
|
||||
// used by mod menu in MC 1.20.6+
|
||||
addModJar(fabricApi.module("fabric-screen-api-v1", rootProject.fabric_api_version))
|
||||
@@ -160,4 +149,4 @@ sourcesJar {
|
||||
def commonSources = project(":common").sourcesJar
|
||||
dependsOn commonSources
|
||||
from commonSources.archiveFile.map { zipTree(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration name="Dev" monitorInterval="10">
|
||||
<Loggers>
|
||||
<Logger name="com.seibel.distanthorizons.core.network" level="trace" additivity="false">
|
||||
<AppenderRef ref="DebugFile" level="${sys:fabric.log.debug.level:-debug}" />
|
||||
<AppenderRef ref="SysOut" />
|
||||
<AppenderRef ref="LatestFile" level="${sys:fabric.log.level:-info}" />
|
||||
<AppenderRef ref="ServerGuiConsole" />
|
||||
</Logger>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
package com.seibel.distanthorizons.fabric;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.seibel.distanthorizons.common.AbstractModInitializer;
|
||||
import com.seibel.distanthorizons.common.AbstractPluginPacketSender;
|
||||
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
@@ -37,24 +38,17 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAcce
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||
import com.seibel.distanthorizons.fabric.wrappers.modAccessor.SodiumAccessor;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
|
||||
#if MC_VER >= MC_1_20_6
|
||||
import com.seibel.distanthorizons.common.CommonPacketPayload;
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
#else
|
||||
import com.seibel.distanthorizons.core.network.messages.NetworkMessage;
|
||||
#endif
|
||||
|
||||
#if MC_VER < MC_1_19_4
|
||||
import java.nio.FloatBuffer;
|
||||
#endif
|
||||
@@ -66,6 +60,7 @@ import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
/**
|
||||
@@ -94,7 +89,6 @@ public class FabricClientProxy implements AbstractModInitializer.IEventProxy
|
||||
* Registers Fabric Events
|
||||
* @author Ran
|
||||
*/
|
||||
@Override
|
||||
public void registerEvents()
|
||||
{
|
||||
LOGGER.info("Registering Fabric Client Events");
|
||||
@@ -252,29 +246,17 @@ public class FabricClientProxy implements AbstractModInitializer.IEventProxy
|
||||
// networking event //
|
||||
//==================//
|
||||
|
||||
#if MC_VER >= MC_1_20_6
|
||||
PayloadTypeRegistry.playC2S().register(CommonPacketPayload.TYPE, new CommonPacketPayload.Codec());
|
||||
PayloadTypeRegistry.playS2C().register(CommonPacketPayload.TYPE, new CommonPacketPayload.Codec());
|
||||
ClientPlayNetworking.registerGlobalReceiver(CommonPacketPayload.TYPE, (payload, context) ->
|
||||
{
|
||||
if (payload.message() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientApi.INSTANCE.pluginMessageReceived(payload.message());
|
||||
});
|
||||
#else
|
||||
ClientPlayNetworking.registerGlobalReceiver(AbstractPluginPacketSender.WRAPPER_PACKET_RESOURCE, (client, handler, buffer, packetSender) ->
|
||||
{
|
||||
// Forge packet ID
|
||||
buffer.readByte();
|
||||
NetworkMessage message = AbstractPluginPacketSender.decodeMessage(buffer);
|
||||
if (message != null)
|
||||
{
|
||||
ClientApi.INSTANCE.pluginMessageReceived(message);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
// ClientPlayNetworking.registerGlobalReceiver(new ResourceLocation(ModInfo.NETWORKING_RESOURCE_NAMESPACE, ModInfo.MULTIVERSE_PLUGIN_NAMESPACE),
|
||||
// (Minecraft client, ClientPacketListener handler, FriendlyByteBuf friendlyByteBuf, PacketSender responseSender) ->
|
||||
// {
|
||||
// // converting to a ByteBuf is necessary otherwise Fabric will complain when the game boots
|
||||
// ByteBuf nettyByteBuf = friendlyByteBuf.asByteBuf();
|
||||
//
|
||||
// // remove the Bukkit/Forge packet ID byte
|
||||
// nettyByteBuf.readByte();
|
||||
//
|
||||
// ClientApi.INSTANCE.serverMessageReceived(nettyByteBuf);
|
||||
// });
|
||||
}
|
||||
|
||||
public void onKeyInput()
|
||||
@@ -303,14 +285,14 @@ public class FabricClientProxy implements AbstractModInitializer.IEventProxy
|
||||
// Diff and trigger events
|
||||
for (int keyCode : currentKeyDown)
|
||||
{
|
||||
if (!this.previouslyPressKeyCodes.contains(keyCode))
|
||||
if (!previouslyPressKeyCodes.contains(keyCode))
|
||||
{
|
||||
ClientApi.INSTANCE.keyPressedEvent(keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the set
|
||||
this.previouslyPressKeyCodes = currentKeyDown;
|
||||
previouslyPressKeyCodes = currentKeyDown;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.*;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import com.seibel.distanthorizons.fabric.wrappers.modAccessor.*;
|
||||
@@ -41,12 +40,6 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
#if MC_VER >= MC_1_19_2
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
#else // < 1.19.2
|
||||
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||
#endif
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.function.Consumer;
|
||||
@@ -58,22 +51,14 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public class FabricMain extends AbstractModInitializer implements ClientModInitializer, DedicatedServerModInitializer
|
||||
{
|
||||
#if MC_VER >= MC_1_21_1
|
||||
private static final ResourceLocation INITIAL_PHASE = ResourceLocation.fromNamespaceAndPath(ModInfo.RESOURCE_NAMESPACE, ModInfo.DEDICATED_SERVER_INITIAL_PATH);
|
||||
#else
|
||||
private static final ResourceLocation INITIAL_PHASE = new ResourceLocation(ModInfo.RESOURCE_NAMESPACE, ModInfo.DEDICATED_SERVER_INITIAL_PATH);
|
||||
#endif
|
||||
private static final ResourceLocation INITIAL_PHASE = ResourceLocation.tryParse("distanthorizons:dedicated_server_initial");
|
||||
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void createInitialBindings()
|
||||
{
|
||||
SingletonInjector.INSTANCE.bind(IModChecker.class, ModChecker.INSTANCE);
|
||||
SingletonInjector.INSTANCE.bind(IPluginPacketSender.class, new FabricPluginPacketSender());
|
||||
}
|
||||
protected void createInitialBindings() { SingletonInjector.INSTANCE.bind(IModChecker.class, ModChecker.INSTANCE); }
|
||||
|
||||
@Override
|
||||
protected IEventProxy createClientProxy() { return new FabricClientProxy(); }
|
||||
@@ -117,12 +102,7 @@ public class FabricMain extends AbstractModInitializer implements ClientModIniti
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void subscribeRegisterCommandsEvent(Consumer<CommandDispatcher<CommandSourceStack>> eventHandler)
|
||||
{
|
||||
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess #if MC_VER >= MC_1_19_2 , environment #endif ) -> {
|
||||
eventHandler.accept(dispatcher);
|
||||
});
|
||||
}
|
||||
protected void subscribeRegisterCommandsEvent(Consumer<CommandDispatcher<CommandSourceStack>> eventHandler) { }
|
||||
|
||||
@Override
|
||||
protected void subscribeClientStartedEvent(Runnable eventHandler) { ClientLifecycleEvents.CLIENT_STARTED.register((mc) -> eventHandler.run()); }
|
||||
@@ -140,21 +120,15 @@ public class FabricMain extends AbstractModInitializer implements ClientModIniti
|
||||
SingletonInjector.INSTANCE.runDelayedSetup();
|
||||
|
||||
if (Config.Client.Advanced.Graphics.Fog.disableVanillaFog.get() && SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("bclib"))
|
||||
{
|
||||
ModAccessorInjector.INSTANCE.get(IBCLibAccessor.class).setRenderCustomFog(false); // Remove BCLib's fog
|
||||
}
|
||||
|
||||
#if MC_VER >= MC_1_20_1
|
||||
if (SingletonInjector.INSTANCE.get(IModChecker.class).isModLoaded("sodium"))
|
||||
{
|
||||
ModAccessorInjector.INSTANCE.get(ISodiumAccessor.class).setFogOcclusion(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ConfigBase.INSTANCE == null)
|
||||
{
|
||||
throw new IllegalStateException("Config was not initialized. Make sure to call LodCommonMain.initConfig() before calling this method.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package com.seibel.distanthorizons.fabric;
|
||||
|
||||
import com.seibel.distanthorizons.common.AbstractPluginPacketSender;
|
||||
import com.seibel.distanthorizons.core.network.messages.NetworkMessage;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
#if MC_VER >= MC_1_20_6
|
||||
import com.seibel.distanthorizons.common.CommonPacketPayload;
|
||||
#else // < 1.20.6
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
#endif
|
||||
|
||||
public class FabricPluginPacketSender extends AbstractPluginPacketSender
|
||||
{
|
||||
@Override
|
||||
public void sendPluginPacketClient(NetworkMessage message)
|
||||
{
|
||||
#if MC_VER >= MC_1_20_6
|
||||
ClientPlayNetworking.send(new CommonPacketPayload(message));
|
||||
#else // < 1.20.6
|
||||
FriendlyByteBuf buffer = PacketByteBufs.create();
|
||||
// Forge packet ID
|
||||
buffer.writeByte(0);
|
||||
AbstractPluginPacketSender.encodeMessage(buffer, message);
|
||||
ClientPlayNetworking.send(WRAPPER_PACKET_RESOURCE, buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPluginPacketServer(ServerPlayer serverPlayer, NetworkMessage message)
|
||||
{
|
||||
#if MC_VER >= MC_1_20_6
|
||||
ServerPlayNetworking.send(serverPlayer, new CommonPacketPayload(message));
|
||||
#else // < 1.20.6
|
||||
FriendlyByteBuf buffer = PacketByteBufs.create();
|
||||
// Forge packet ID
|
||||
buffer.writeByte(0);
|
||||
AbstractPluginPacketSender.encodeMessage(buffer, message);
|
||||
ServerPlayNetworking.send(serverPlayer, WRAPPER_PACKET_RESOURCE, buffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,13 +13,11 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.fabric.testing.TestWorldGenBindingEvent;
|
||||
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityWorldChangeEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerChunkEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
@@ -27,14 +25,6 @@ import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
#if MC_VER >= MC_1_20_6
|
||||
import com.seibel.distanthorizons.common.CommonPacketPayload;
|
||||
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||
#else
|
||||
import com.seibel.distanthorizons.core.network.messages.NetworkMessage;
|
||||
import com.seibel.distanthorizons.common.AbstractPluginPacketSender;
|
||||
#endif
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -64,7 +54,7 @@ public class FabricServerProxy implements AbstractModInitializer.IEventProxy
|
||||
|
||||
private boolean isValidTime()
|
||||
{
|
||||
if (this.isDedicated)
|
||||
if (isDedicated)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -78,7 +68,6 @@ public class FabricServerProxy implements AbstractModInitializer.IEventProxy
|
||||
private ServerPlayerWrapper getServerPlayerWrapper(ServerPlayer player) { return ServerPlayerWrapper.getWrapper(player); }
|
||||
|
||||
/** Registers Fabric Events */
|
||||
@Override
|
||||
public void registerEvents()
|
||||
{
|
||||
LOGGER.info("Registering Fabric Server Events");
|
||||
@@ -101,15 +90,15 @@ public class FabricServerProxy implements AbstractModInitializer.IEventProxy
|
||||
//TODO: Check if both of these use the correct timed events. (i.e. is it 'ed' or 'ing' one?)
|
||||
ServerLifecycleEvents.SERVER_STARTING.register((server) ->
|
||||
{
|
||||
if (this.isValidTime())
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverLoadEvent(this.isDedicated);
|
||||
ServerApi.INSTANCE.serverLoadEvent(isDedicated);
|
||||
}
|
||||
});
|
||||
// ServerWorldUnloadEvent
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register((server) ->
|
||||
{
|
||||
if (this.isValidTime())
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverUnloadEvent();
|
||||
}
|
||||
@@ -118,25 +107,25 @@ public class FabricServerProxy implements AbstractModInitializer.IEventProxy
|
||||
// ServerLevelLoadEvent
|
||||
ServerWorldEvents.LOAD.register((server, level) ->
|
||||
{
|
||||
if (this.isValidTime())
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverLevelLoadEvent(this.getServerLevelWrapper(level));
|
||||
ServerApi.INSTANCE.serverLevelLoadEvent(getServerLevelWrapper(level));
|
||||
}
|
||||
});
|
||||
// ServerLevelUnloadEvent
|
||||
ServerWorldEvents.UNLOAD.register((server, level) ->
|
||||
{
|
||||
if (this.isValidTime())
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverLevelUnloadEvent(this.getServerLevelWrapper(level));
|
||||
ServerApi.INSTANCE.serverLevelUnloadEvent(getServerLevelWrapper(level));
|
||||
}
|
||||
});
|
||||
|
||||
// ServerChunkLoadEvent
|
||||
ServerChunkEvents.CHUNK_LOAD.register((server, chunk) ->
|
||||
{
|
||||
ILevelWrapper level = this.getServerLevelWrapper((ServerLevel) chunk.getLevel());
|
||||
if (this.isValidTime())
|
||||
ILevelWrapper level = getServerLevelWrapper((ServerLevel) chunk.getLevel());
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverChunkLoadEvent(
|
||||
new ChunkWrapper(chunk, chunk.getLevel(), level),
|
||||
@@ -147,56 +136,18 @@ public class FabricServerProxy implements AbstractModInitializer.IEventProxy
|
||||
|
||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) ->
|
||||
{
|
||||
if (this.isValidTime())
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverPlayerJoinEvent(this.getServerPlayerWrapper(handler.player));
|
||||
ServerApi.INSTANCE.serverPlayerJoinEvent(getServerPlayerWrapper(handler.player));
|
||||
}
|
||||
});
|
||||
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) ->
|
||||
{
|
||||
if (this.isValidTime())
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverPlayerDisconnectEvent(this.getServerPlayerWrapper(handler.player));
|
||||
ServerApi.INSTANCE.serverPlayerDisconnectEvent(getServerPlayerWrapper(handler.player));
|
||||
}
|
||||
});
|
||||
ServerEntityWorldChangeEvents.AFTER_PLAYER_CHANGE_WORLD.register((player, origin, dest) ->
|
||||
{
|
||||
if (this.isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverPlayerLevelChangeEvent(
|
||||
this.getServerPlayerWrapper(player),
|
||||
this.getServerLevelWrapper(origin),
|
||||
this.getServerLevelWrapper(dest)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.isDedicated)
|
||||
{
|
||||
#if MC_VER >= MC_1_20_6
|
||||
PayloadTypeRegistry.playC2S().register(CommonPacketPayload.TYPE, new CommonPacketPayload.Codec());
|
||||
PayloadTypeRegistry.playS2C().register(CommonPacketPayload.TYPE, new CommonPacketPayload.Codec());
|
||||
ServerPlayNetworking.registerGlobalReceiver(CommonPacketPayload.TYPE, (payload, context) ->
|
||||
{
|
||||
if (payload.message() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ServerApi.INSTANCE.pluginMessageReceived(ServerPlayerWrapper.getWrapper(context.player()), payload.message());
|
||||
});
|
||||
#else
|
||||
ServerPlayNetworking.registerGlobalReceiver(AbstractPluginPacketSender.WRAPPER_PACKET_RESOURCE, (server, serverPlayer, handler, buffer, packetSender) ->
|
||||
{
|
||||
// Forge packet ID
|
||||
buffer.readByte();
|
||||
NetworkMessage message = AbstractPluginPacketSender.decodeMessage(buffer);
|
||||
if (message != null)
|
||||
{
|
||||
ServerApi.INSTANCE.pluginMessageReceived(ServerPlayerWrapper.getWrapper(serverPlayer), message);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -65,4 +65,4 @@ public class MixinClientLevel
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+29
-1
@@ -21,9 +21,33 @@ import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
@Mixin(ClientPacketListener.class)
|
||||
public class MixinClientPacketListener
|
||||
{
|
||||
@Shadow
|
||||
private ClientLevel level;
|
||||
|
||||
@Unique
|
||||
private ClientLevel previousLevel;
|
||||
|
||||
|
||||
@Inject(method = "handleLogin", at = @At("RETURN"))
|
||||
void onHandleLoginEnd(CallbackInfo ci) { ClientApi.INSTANCE.onClientOnlyConnected(); }
|
||||
|
||||
@Inject(method = "handleRespawn", at = @At("HEAD"))
|
||||
void onHandleRespawnStart(CallbackInfo ci) { this.previousLevel = this.level; }
|
||||
@Inject(method = "handleRespawn", at = @At("RETURN"))
|
||||
void onHandleRespawnEnd(CallbackInfo ci)
|
||||
{
|
||||
// If the player changes dimensions the "this.level" will be changed halfway through the respawn method.
|
||||
// By checking if the object references are the same, we can see if the previous level should be unloaded
|
||||
// or if the player just respawned in the same level.
|
||||
if (this.previousLevel != this.level)
|
||||
{
|
||||
ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(this.previousLevel));
|
||||
ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper(this.level));
|
||||
}
|
||||
|
||||
this.previousLevel = null;
|
||||
}
|
||||
|
||||
#if MC_VER < MC_1_19_4
|
||||
@Inject(method = "cleanup", at = @At("HEAD"))
|
||||
#else
|
||||
@@ -31,6 +55,10 @@ public class MixinClientPacketListener
|
||||
#endif
|
||||
void onCleanupStart(CallbackInfo ci)
|
||||
{
|
||||
if (this.level != null)
|
||||
{
|
||||
ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(this.level));
|
||||
}
|
||||
ClientApi.INSTANCE.onClientOnlyDisconnected();
|
||||
}
|
||||
|
||||
@@ -44,4 +72,4 @@ public class MixinClientPacketListener
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+2
-26
@@ -2,8 +2,6 @@ package com.seibel.distanthorizons.fabric.mixins.client;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.config.EDhApiUpdateBranch;
|
||||
import com.seibel.distanthorizons.common.wrappers.gui.updater.UpdateModScreen;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.jar.installer.GitlabGetter;
|
||||
@@ -14,9 +12,7 @@ import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@@ -29,14 +25,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
* @author coolGi
|
||||
*/
|
||||
@Mixin(Minecraft.class)
|
||||
public abstract class MixinMinecraft
|
||||
public class MixinMinecraft
|
||||
{
|
||||
@Shadow
|
||||
public abstract boolean isLocalServer();
|
||||
|
||||
@Unique
|
||||
private ClientLevel lastLevel;
|
||||
|
||||
/**
|
||||
* Can be enabled for testing the auto updater UI. <br/>
|
||||
* will always show the auto updater if set to true.
|
||||
@@ -123,21 +113,7 @@ public abstract class MixinMinecraft
|
||||
}
|
||||
#endif
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "updateLevelInEngines")
|
||||
public void updateLevelInEngines(ClientLevel level, CallbackInfo ci)
|
||||
{
|
||||
if (this.lastLevel != null && level != this.lastLevel)
|
||||
{
|
||||
ClientApi.INSTANCE.clientLevelUnloadEvent(ClientLevelWrapper.getWrapper(this.lastLevel));
|
||||
}
|
||||
if (level != null)
|
||||
{
|
||||
ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper(level, true));
|
||||
}
|
||||
this.lastLevel = level;
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "close()V")
|
||||
public void close(CallbackInfo ci) { SelfUpdater.onClose(); }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2023 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.fabric.mixins.server;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.IMixinServerPlayer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
#if MC_VER >= MC_1_21_1
|
||||
import net.minecraft.world.level.portal.DimensionTransition;
|
||||
#endif
|
||||
|
||||
|
||||
@Mixin(ServerPlayer.class)
|
||||
public class MixinServerPlayer implements IMixinServerPlayer
|
||||
{
|
||||
@Unique
|
||||
@Nullable
|
||||
private ServerLevel dimensionChangeDestination;
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ServerLevel distantHorizons$getDimensionChangeDestination()
|
||||
{
|
||||
return this.dimensionChangeDestination;
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "changeDimension")
|
||||
#if MC_VER >= MC_1_21_1
|
||||
public void changeDimension(DimensionTransition dimensionTransition, CallbackInfoReturnable<Entity> cir)
|
||||
{
|
||||
this.dimensionChangeDestination = dimensionTransition.newLevel();
|
||||
}
|
||||
#else
|
||||
public void changeDimension(ServerLevel destination, CallbackInfoReturnable<Entity> cir)
|
||||
{
|
||||
this.dimensionChangeDestination = destination;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MC_VER >= MC_1_20_1
|
||||
@Inject(at = @At("RETURN"), method = "setServerLevel")
|
||||
public void setServerLevel(ServerLevel level, CallbackInfo ci)
|
||||
#else
|
||||
@Inject(at = @At("RETURN"), method = "setLevel")
|
||||
public void setLevel(ServerLevel level, CallbackInfo ci)
|
||||
#endif
|
||||
{
|
||||
this.dimensionChangeDestination = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,8 +5,7 @@
|
||||
"mixins": [
|
||||
"server.MixinChunkGenerator",
|
||||
"server.MixinChunkMap",
|
||||
"server.MixinUtilBackgroundThread",
|
||||
"server.MixinServerPlayer"
|
||||
"server.MixinUtilBackgroundThread"
|
||||
],
|
||||
"client": [
|
||||
"client.MixinClientLevel",
|
||||
@@ -25,4 +24,4 @@
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"plugin": "com.seibel.distanthorizons.fabric.mixins.FabricMixinPlugin"
|
||||
}
|
||||
}
|
||||
|
||||
+5
-7
@@ -37,17 +37,15 @@ loom {
|
||||
client {
|
||||
client()
|
||||
setConfigName("Forge Client")
|
||||
ideConfigGenerated(false)
|
||||
runDir("../run/client")
|
||||
vmArgs("-Dio.netty.leakDetection.level=advanced")
|
||||
programArgs("--username", "Dev")
|
||||
ideConfigGenerated(true)
|
||||
runDir("../run")
|
||||
// vmArgs("-XX:-OmitStackTraceInFastThrow", minecraftMemoryJavaArg)
|
||||
}
|
||||
server {
|
||||
server()
|
||||
setConfigName("Forge Server")
|
||||
ideConfigGenerated(false)
|
||||
runDir("../run/server")
|
||||
vmArgs("-Dio.netty.leakDetection.level=advanced")
|
||||
ideConfigGenerated(true)
|
||||
runDir("../run")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
//import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
@@ -51,6 +53,8 @@ import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
//import net.minecraftforge.network.NetworkRegistry;
|
||||
//import net.minecraftforge.network.simple.SimpleChannel;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
@@ -75,6 +79,8 @@ public class ForgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
{
|
||||
private static final IMinecraftClientWrapper MC = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
// private static SimpleChannel multiversePluginChannel;
|
||||
|
||||
|
||||
#if MC_VER < MC_1_19_2
|
||||
@@ -89,7 +95,7 @@ public class ForgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
public void registerEvents()
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
ForgePluginPacketSender.setPacketHandler(ClientApi.INSTANCE::pluginMessageReceived);
|
||||
this.setupNetworkingListeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -121,7 +127,7 @@ public class ForgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
#endif
|
||||
{
|
||||
LOGGER.info("level load");
|
||||
|
||||
|
||||
#if MC_VER < MC_1_19_2
|
||||
LevelAccessor level = event.getWorld();
|
||||
#else
|
||||
@@ -133,7 +139,7 @@ public class ForgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
}
|
||||
|
||||
ClientLevel clientLevel = (ClientLevel) level;
|
||||
IClientLevelWrapper clientLevelWrapper = ClientLevelWrapper.getWrapper(clientLevel, true);
|
||||
IClientLevelWrapper clientLevelWrapper = ClientLevelWrapper.getWrapper(clientLevel);
|
||||
// TODO this causes a crash due to level being set to null somewhere
|
||||
ClientApi.INSTANCE.clientLevelLoadEvent(clientLevelWrapper);
|
||||
}
|
||||
@@ -145,7 +151,7 @@ public class ForgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
#endif
|
||||
{
|
||||
LOGGER.info("level unload");
|
||||
|
||||
|
||||
#if MC_VER < MC_1_19_2
|
||||
LevelAccessor level = event.getWorld();
|
||||
#else
|
||||
@@ -264,6 +270,66 @@ public class ForgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============//
|
||||
// networking //
|
||||
//============//
|
||||
|
||||
public void setupNetworkingListeners()
|
||||
{
|
||||
// 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) ->
|
||||
// {
|
||||
// ClientApi.INSTANCE.serverMessageReceived(nettyByteBuf);
|
||||
// contextRef.get().setPacketHandled(true);
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
public static boolean isReceivedProtocolVersionAcceptable(String versionString)
|
||||
{
|
||||
if (versionString.toLowerCase().contains("allowvanilla"))
|
||||
{
|
||||
// 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
|
||||
try
|
||||
{
|
||||
int version = Integer.parseInt(versionString);
|
||||
return ModInfo.MULTIVERSE_PLUGIN_PROTOCOL_VERSION == version;
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===========//
|
||||
// rendering //
|
||||
//===========//
|
||||
@@ -297,4 +363,5 @@ public class ForgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ import com.seibel.distanthorizons.common.wrappers.gui.GetConfigScreen;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.common.wrappers.gui.GetConfigScreen;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
|
||||
@@ -38,16 +36,15 @@ import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.eventbus.api.EventPriority;
|
||||
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.FMLServerAboutToStartEvent;
|
||||
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
||||
#elif MC_VER == MC_1_17_1
|
||||
import net.minecraftforge.fmlserverevents.FMLServerAboutToStartEvent;
|
||||
import net.minecraftforge.fmlserverevents.FMLServerStartingEvent;
|
||||
#else
|
||||
import net.minecraftforge.event.server.ServerAboutToStartEvent;
|
||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||
#endif
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
#if MC_VER < MC_1_17_1
|
||||
@@ -86,11 +83,7 @@ public class ForgeMain extends AbstractModInitializer
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createInitialBindings()
|
||||
{
|
||||
SingletonInjector.INSTANCE.bind(IModChecker.class, ModChecker.INSTANCE);
|
||||
SingletonInjector.INSTANCE.bind(IPluginPacketSender.class, new ForgePluginPacketSender());
|
||||
}
|
||||
protected void createInitialBindings() { SingletonInjector.INSTANCE.bind(IModChecker.class, ModChecker.INSTANCE); }
|
||||
|
||||
@Override
|
||||
protected IEventProxy createClientProxy() { return new ForgeClientProxy(); }
|
||||
@@ -144,7 +137,7 @@ public class ForgeMain extends AbstractModInitializer
|
||||
@Override
|
||||
protected void subscribeServerStartingEvent(Consumer<MinecraftServer> eventHandler)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, (#if MC_VER >= MC_1_18_2 ServerAboutToStartEvent #else FMLServerAboutToStartEvent #endif e) ->
|
||||
MinecraftForge.EVENT_BUS.addListener((#if MC_VER >= MC_1_18_2 ServerStartingEvent #else FMLServerStartingEvent #endif e) ->
|
||||
{
|
||||
eventHandler.accept(e.getServer());
|
||||
});
|
||||
@@ -153,4 +146,4 @@ public class ForgeMain extends AbstractModInitializer
|
||||
@Override
|
||||
protected void runDelayedSetup() { SingletonInjector.INSTANCE.runDelayedSetup(); }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
package com.seibel.distanthorizons.forge;
|
||||
|
||||
import com.seibel.distanthorizons.common.AbstractPluginPacketSender;
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.core.network.messages.NetworkMessage;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
#if MC_VER >= MC_1_20_2
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
import net.minecraftforge.network.ChannelBuilder;
|
||||
import net.minecraftforge.network.SimpleChannel;
|
||||
#elif MC_VER >= MC_1_18_2
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
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.PacketDistributor;
|
||||
import net.minecraftforge.fmllegacy.network.simple.SimpleChannel;
|
||||
#else // < 1.17.1
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
#endif
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ForgePluginPacketSender extends AbstractPluginPacketSender
|
||||
{
|
||||
public static final SimpleChannel PLUGIN_CHANNEL =
|
||||
#if MC_VER >= MC_1_20_2
|
||||
ChannelBuilder.named(AbstractPluginPacketSender.WRAPPER_PACKET_RESOURCE)
|
||||
.networkProtocolVersion(1)
|
||||
.serverAcceptedVersions((status, version) -> true)
|
||||
.clientAcceptedVersions((status, version) -> true)
|
||||
.simpleChannel();
|
||||
#else // < 1.20.2
|
||||
NetworkRegistry.newSimpleChannel(
|
||||
AbstractPluginPacketSender.WRAPPER_PACKET_RESOURCE,
|
||||
() -> "1",
|
||||
ignored -> true,
|
||||
ignored -> true
|
||||
);
|
||||
#endif
|
||||
|
||||
public static void setPacketHandler(Consumer<NetworkMessage> consumer)
|
||||
{
|
||||
setPacketHandler((player, message) -> consumer.accept(message));
|
||||
}
|
||||
public static void setPacketHandler(BiConsumer<IServerPlayerWrapper, NetworkMessage> consumer)
|
||||
{
|
||||
#if MC_VER >= MC_1_20_2
|
||||
PLUGIN_CHANNEL.messageBuilder(MessageWrapper.class, 0)
|
||||
.encoder((wrapper, out) -> AbstractPluginPacketSender.encodeMessage(out, wrapper.message))
|
||||
.decoder(in -> new MessageWrapper(AbstractPluginPacketSender.decodeMessage(in)))
|
||||
.consumerNetworkThread((wrapper, context) ->
|
||||
{
|
||||
if (wrapper.message != null)
|
||||
{
|
||||
if (context.getSender() != null)
|
||||
{
|
||||
consumer.accept(ServerPlayerWrapper.getWrapper(context.getSender()), wrapper.message);
|
||||
}
|
||||
else
|
||||
{
|
||||
consumer.accept(null, wrapper.message);
|
||||
}
|
||||
}
|
||||
context.setPacketHandled(true);
|
||||
})
|
||||
.add();
|
||||
#else // < 1.20.2
|
||||
PLUGIN_CHANNEL.registerMessage(0, MessageWrapper.class,
|
||||
(wrapper, out) -> AbstractPluginPacketSender.encodeMessage(out, wrapper.message),
|
||||
in -> new MessageWrapper(AbstractPluginPacketSender.decodeMessage(in)),
|
||||
(wrapper, context) ->
|
||||
{
|
||||
if (wrapper.message != null)
|
||||
{
|
||||
if (context.get().getSender() != null)
|
||||
{
|
||||
consumer.accept(ServerPlayerWrapper.getWrapper(context.get().getSender()), wrapper.message);
|
||||
}
|
||||
else
|
||||
{
|
||||
consumer.accept(null, wrapper.message);
|
||||
}
|
||||
}
|
||||
context.get().setPacketHandled(true);
|
||||
}
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPluginPacketClient(NetworkMessage message)
|
||||
{
|
||||
#if MC_VER >= MC_1_20_2
|
||||
PLUGIN_CHANNEL.send(new MessageWrapper(message), PacketDistributor.SERVER.noArg());
|
||||
#else // < 1.20.2
|
||||
PLUGIN_CHANNEL.send(PacketDistributor.SERVER.noArg(), new MessageWrapper(message));
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPluginPacketServer(ServerPlayer serverPlayer, NetworkMessage message)
|
||||
{
|
||||
#if MC_VER >= MC_1_20_2
|
||||
PLUGIN_CHANNEL.send(new MessageWrapper(message), PacketDistributor.PLAYER.with(serverPlayer));
|
||||
#else // < 1.20.2
|
||||
PLUGIN_CHANNEL.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new MessageWrapper(message));
|
||||
#endif
|
||||
}
|
||||
|
||||
// Forge doesn't support using abstract classes
|
||||
@SuppressWarnings({"ClassCanBeRecord", "RedundantSuppression"})
|
||||
public static class MessageWrapper
|
||||
{
|
||||
public final NetworkMessage message;
|
||||
|
||||
public MessageWrapper(NetworkMessage message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,20 +3,16 @@ package com.seibel.distanthorizons.forge;
|
||||
import com.seibel.distanthorizons.common.AbstractModInitializer;
|
||||
import com.seibel.distanthorizons.common.util.ProxyUtil;
|
||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||
import com.seibel.distanthorizons.core.api.internal.ServerApi;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
#if MC_VER < MC_1_19_2
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
@@ -26,13 +22,6 @@ import net.minecraftforge.event.level.LevelEvent;
|
||||
#endif
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
#if MC_VER >= MC_1_19_4
|
||||
import net.minecraft.core.registries.Registries;
|
||||
#else // < 1.19.4
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
#endif
|
||||
|
||||
#if MC_VER == MC_1_16_5
|
||||
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
|
||||
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent;
|
||||
@@ -58,6 +47,7 @@ public class ForgeServerProxy implements AbstractModInitializer.IEventProxy
|
||||
#endif
|
||||
|
||||
private final ServerApi serverApi = ServerApi.INSTANCE;
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
private final boolean isDedicated;
|
||||
public static Supplier<Boolean> isGenerationThreadChecker = null;
|
||||
|
||||
@@ -67,10 +57,6 @@ public class ForgeServerProxy implements AbstractModInitializer.IEventProxy
|
||||
public void registerEvents()
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
if (this.isDedicated)
|
||||
{
|
||||
ForgePluginPacketSender.setPacketHandler(ServerApi.INSTANCE::pluginMessageReceived);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +111,7 @@ public class ForgeServerProxy implements AbstractModInitializer.IEventProxy
|
||||
{
|
||||
if (GetEventLevel(event) instanceof ServerLevel)
|
||||
{
|
||||
this.serverApi.serverLevelLoadEvent(getServerLevelWrapper((ServerLevel) GetEventLevel(event)));
|
||||
this.serverApi.serverLevelLoadEvent(this.getServerLevelWrapper((ServerLevel) GetEventLevel(event)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +125,7 @@ public class ForgeServerProxy implements AbstractModInitializer.IEventProxy
|
||||
{
|
||||
if (GetEventLevel(event) instanceof ServerLevel)
|
||||
{
|
||||
this.serverApi.serverLevelUnloadEvent(getServerLevelWrapper((ServerLevel) GetEventLevel(event)));
|
||||
this.serverApi.serverLevelUnloadEvent(this.getServerLevelWrapper((ServerLevel) GetEventLevel(event)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,26 +138,6 @@ public class ForgeServerProxy implements AbstractModInitializer.IEventProxy
|
||||
this.serverApi.serverChunkLoadEvent(chunk, levelWrapper);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent event)
|
||||
{
|
||||
this.serverApi.serverPlayerJoinEvent(getServerPlayerWrapper(event));
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void playerLoggedOutEvent(PlayerEvent.PlayerLoggedOutEvent event)
|
||||
{
|
||||
this.serverApi.serverPlayerDisconnectEvent(getServerPlayerWrapper(event));
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void playerChangedDimensionEvent(PlayerEvent.PlayerChangedDimensionEvent event)
|
||||
{
|
||||
this.serverApi.serverPlayerLevelChangeEvent(
|
||||
getServerPlayerWrapper(event),
|
||||
getServerLevelWrapper(event.getFrom(), event),
|
||||
getServerLevelWrapper(event.getTo(), event)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
@@ -181,20 +147,4 @@ public class ForgeServerProxy implements AbstractModInitializer.IEventProxy
|
||||
private static ServerLevelWrapper getServerLevelWrapper(ServerLevel level) { return ServerLevelWrapper.getWrapper(level); }
|
||||
|
||||
|
||||
private static ServerLevelWrapper getServerLevelWrapper(ResourceKey<Level> resourceKey, PlayerEvent event)
|
||||
{
|
||||
//noinspection DataFlowIssue (possible NPE after getServer())
|
||||
return getServerLevelWrapper(event.getEntity().getServer().getLevel(resourceKey));
|
||||
}
|
||||
|
||||
private static ServerPlayerWrapper getServerPlayerWrapper(PlayerEvent event) {
|
||||
return ServerPlayerWrapper.getWrapper(
|
||||
#if MC_VER >= MC_1_19_2
|
||||
(ServerPlayer) event.getEntity()
|
||||
#else
|
||||
(ServerPlayer) event.getPlayer()
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -26,4 +26,4 @@ public class MixinClientPacketListener
|
||||
ClientApi.INSTANCE.onClientOnlyDisconnected();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -2,8 +2,6 @@ package com.seibel.distanthorizons.forge.mixins.client;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.config.EDhApiUpdateBranch;
|
||||
import com.seibel.distanthorizons.common.wrappers.gui.updater.UpdateModScreen;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.jar.installer.GitlabGetter;
|
||||
@@ -13,9 +11,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@@ -108,4 +104,4 @@ public class MixinMinecraft
|
||||
SelfUpdater.onClose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2023 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.forge.mixins.server;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.IMixinServerPlayer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraftforge.common.util.ITeleporter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
|
||||
@Mixin(ServerPlayer.class)
|
||||
public class MixinServerPlayer implements IMixinServerPlayer
|
||||
{
|
||||
@Unique
|
||||
@Nullable
|
||||
private volatile ServerLevel distantHorizons$dimensionChangeDestination;
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ServerLevel distantHorizons$getDimensionChangeDestination()
|
||||
{
|
||||
return this.distantHorizons$dimensionChangeDestination;
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "changeDimension", remap = false)
|
||||
public void changeDimension(ServerLevel destination, ITeleporter teleporter, CallbackInfoReturnable<Entity> cir)
|
||||
{
|
||||
this.distantHorizons$dimensionChangeDestination = destination;
|
||||
}
|
||||
|
||||
#if MC_VER >= MC_1_20_1
|
||||
@Inject(at = @At("RETURN"), method = "setServerLevel")
|
||||
public void setServerLevel(ServerLevel level, CallbackInfo ci)
|
||||
#else
|
||||
@Inject(at = @At("RETURN"), method = "setLevel")
|
||||
public void setLevel(ServerLevel level, CallbackInfo ci)
|
||||
#endif
|
||||
{
|
||||
this.distantHorizons$dimensionChangeDestination = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,8 +6,7 @@
|
||||
"server.MixinUtilBackgroundThread",
|
||||
"server.MixinChunkGenerator",
|
||||
"server.MixinTFChunkGenerator",
|
||||
"server.MixinChunkMap",
|
||||
"server.MixinServerPlayer"
|
||||
"server.MixinChunkMap"
|
||||
],
|
||||
"client": [
|
||||
"client.MixinClientPacketListener",
|
||||
|
||||
+3
-2
@@ -5,7 +5,7 @@ org.gradle.caching=true
|
||||
|
||||
# Mod Info
|
||||
mod_name=DistantHorizons
|
||||
mod_version=2.2.2-a-dev
|
||||
mod_version=2.2.1-a
|
||||
api_version=3.0.0
|
||||
maven_group=com.seibel.distanthorizons
|
||||
mod_readable_name=Distant Horizons
|
||||
@@ -31,6 +31,7 @@ fastutil_version=8.2.1
|
||||
|
||||
# Minecraft related libraries (included in MC's jar)
|
||||
log4j_version=2.23.1
|
||||
netty_version=4.1.94.Final
|
||||
lwjgl_version=3.3.1
|
||||
joml_version=1.10.2
|
||||
|
||||
@@ -51,4 +52,4 @@ versionStr=
|
||||
mcVer=1.21.1
|
||||
|
||||
# Defines the maximum amount of memory Minecraft is allowed when run in a development environment
|
||||
#minecraftMemoryJavaArg="-Xmx4G"
|
||||
#minecraftMemoryJavaArg="-Xmx4G"
|
||||
|
||||
@@ -29,17 +29,15 @@ loom {
|
||||
client {
|
||||
client()
|
||||
setConfigName("NeoForge Client")
|
||||
ideConfigGenerated(false)
|
||||
runDir("../run/client")
|
||||
vmArgs("-Dio.netty.leakDetection.level=advanced")
|
||||
programArgs("--username", "Dev")
|
||||
ideConfigGenerated(true)
|
||||
runDir("../run")
|
||||
//vmArgs("-XX:-OmitStackTraceInFastThrow", minecraftMemoryJavaArg)
|
||||
}
|
||||
server {
|
||||
server()
|
||||
setConfigName("NeoForge Server")
|
||||
ideConfigGenerated(false)
|
||||
runDir("../run/server")
|
||||
vmArgs("-Dio.netty.leakDetection.level=advanced")
|
||||
ideConfigGenerated(true)
|
||||
runDir("../run")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,4 +97,4 @@ sourcesJar {
|
||||
def commonSources = project(":common").sourcesJar
|
||||
dependsOn commonSources
|
||||
from commonSources.archiveFile.map { zipTree(it) }
|
||||
}
|
||||
}
|
||||
|
||||
+65
-2
@@ -35,6 +35,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
@@ -46,6 +47,8 @@ import net.neoforged.neoforge.event.level.LevelEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
|
||||
//import net.neoforged.network.NetworkRegistry;
|
||||
//import net.neoforged.network.simple.SimpleChannel;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
@@ -90,6 +93,7 @@ public class NeoforgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
public void registerEvents()
|
||||
{
|
||||
NeoForge.EVENT_BUS.register(this);
|
||||
setupNetworkingListeners();
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +137,7 @@ public class NeoforgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
}
|
||||
|
||||
ClientLevel clientLevel = (ClientLevel) level;
|
||||
IClientLevelWrapper clientLevelWrapper = ClientLevelWrapper.getWrapper(clientLevel, true);
|
||||
IClientLevelWrapper clientLevelWrapper = ClientLevelWrapper.getWrapper(clientLevel);
|
||||
// TODO this causes a crash due to level being set to null somewhere
|
||||
ClientApi.INSTANCE.clientLevelLoadEvent(clientLevelWrapper);
|
||||
}
|
||||
@@ -242,6 +246,65 @@ public class NeoforgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
|
||||
|
||||
|
||||
//============//
|
||||
// networking //
|
||||
//============//
|
||||
|
||||
public static void setupNetworkingListeners()
|
||||
{
|
||||
// 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) ->
|
||||
// {
|
||||
// ClientApi.INSTANCE.serverMessageReceived(nettyByteBuf);
|
||||
// contextRef.get().setPacketHandled(true);
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
public static boolean isReceivedProtocolVersionAcceptable(String versionString)
|
||||
{
|
||||
if (versionString.toLowerCase().contains("allowvanilla"))
|
||||
{
|
||||
// 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
|
||||
try
|
||||
{
|
||||
int version = Integer.parseInt(versionString);
|
||||
return ModInfo.MULTIVERSE_PLUGIN_PROTOCOL_VERSION == version;
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===========//
|
||||
// rendering //
|
||||
//===========//
|
||||
@@ -284,4 +347,4 @@ public class NeoforgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
private static LevelAccessor GetEventLevel(LevelEvent e) { return e.getLevel(); }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,7 @@ import com.seibel.distanthorizons.common.AbstractModInitializer;
|
||||
import com.seibel.distanthorizons.common.wrappers.gui.GetConfigScreen;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.api.internal.ServerApi;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
|
||||
import com.seibel.distanthorizons.coreapi.ModInfo;
|
||||
@@ -34,7 +32,6 @@ import com.seibel.distanthorizons.neoforge.wrappers.modAccessor.ModChecker;
|
||||
import com.seibel.distanthorizons.neoforge.wrappers.modAccessor.OptifineAccessor;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.neoforged.bus.api.EventPriority;
|
||||
import net.neoforged.bus.api.IEventBus;
|
||||
import net.neoforged.fml.ModLoadingContext;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
@@ -43,14 +40,13 @@ import net.neoforged.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStartingEvent;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
#if MC_VER < MC_1_20_6
|
||||
import net.neoforged.neoforge.client.ConfigScreenHandler;
|
||||
#else
|
||||
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
||||
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -59,46 +55,19 @@ import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
|
||||
* check out the ClientProxy.
|
||||
*/
|
||||
@Mod(ModInfo.ID)
|
||||
@SuppressWarnings("unused")
|
||||
public class NeoforgeMain extends AbstractModInitializer
|
||||
{
|
||||
public NeoforgeMain(IEventBus eventBus)
|
||||
{
|
||||
eventBus.addListener((FMLClientSetupEvent e) -> {
|
||||
this.onInitializeClient();
|
||||
eventBus.addListener(this::registerNetworkingClient);
|
||||
});
|
||||
eventBus.addListener((FMLDedicatedServerSetupEvent e) -> {
|
||||
this.onInitializeServer();
|
||||
eventBus.addListener(this::registerNetworkingServer);
|
||||
});
|
||||
eventBus.addListener((FMLClientSetupEvent e) -> this.onInitializeClient());
|
||||
eventBus.addListener((FMLDedicatedServerSetupEvent e) -> this.onInitializeServer());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============//
|
||||
// networking //
|
||||
//============//
|
||||
public void registerNetworkingClient(RegisterPayloadHandlersEvent event)
|
||||
{
|
||||
NeoforgePluginPacketSender.setPacketHandler(event, ClientApi.INSTANCE::pluginMessageReceived);
|
||||
}
|
||||
public void registerNetworkingServer(RegisterPayloadHandlersEvent event)
|
||||
{
|
||||
NeoforgePluginPacketSender.setPacketHandler(event, ServerApi.INSTANCE::pluginMessageReceived);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected IEventProxy createServerProxy(boolean isDedicated) { return new NeoforgeServerProxy(isDedicated); }
|
||||
|
||||
@Override
|
||||
protected void createInitialBindings()
|
||||
{
|
||||
SingletonInjector.INSTANCE.bind(IModChecker.class, ModChecker.INSTANCE);
|
||||
SingletonInjector.INSTANCE.bind(IPluginPacketSender.class, new NeoforgePluginPacketSender());
|
||||
}
|
||||
protected void createInitialBindings() { SingletonInjector.INSTANCE.bind(IModChecker.class, ModChecker.INSTANCE); }
|
||||
|
||||
@Override
|
||||
protected IEventProxy createClientProxy() { return new NeoforgeClientProxy(); }
|
||||
@@ -147,10 +116,10 @@ public class NeoforgeMain extends AbstractModInitializer
|
||||
@Override
|
||||
protected void subscribeServerStartingEvent(Consumer<MinecraftServer> eventHandler)
|
||||
{
|
||||
NeoForge.EVENT_BUS.addListener(EventPriority.HIGH, (ServerStartingEvent e) -> { eventHandler.accept(e.getServer()); });
|
||||
NeoForge.EVENT_BUS.addListener((ServerStartingEvent e) -> { eventHandler.accept(e.getServer()); });
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runDelayedSetup() { SingletonInjector.INSTANCE.runDelayedSetup(); }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
package com.seibel.distanthorizons.neoforge;
|
||||
|
||||
import com.seibel.distanthorizons.common.CommonPacketPayload;
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.common.AbstractPluginPacketSender;
|
||||
import com.seibel.distanthorizons.core.network.messages.NetworkMessage;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.neoforged.neoforge.network.PacketDistributor;
|
||||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||
import net.neoforged.neoforge.network.registration.PayloadRegistrar;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class NeoforgePluginPacketSender extends AbstractPluginPacketSender
|
||||
{
|
||||
private static BiConsumer<IServerPlayerWrapper, NetworkMessage> packetConsumer;
|
||||
|
||||
public static void setPacketHandler(RegisterPayloadHandlersEvent event, Consumer<NetworkMessage> consumer)
|
||||
{
|
||||
setPacketHandler(event, (player, buffer) -> consumer.accept(buffer));
|
||||
}
|
||||
public static void setPacketHandler(RegisterPayloadHandlersEvent event, BiConsumer<IServerPlayerWrapper, NetworkMessage> consumer)
|
||||
{
|
||||
packetConsumer = consumer;
|
||||
|
||||
PayloadRegistrar registrar = event.registrar("1").optional();
|
||||
registrar.playBidirectional(CommonPacketPayload.TYPE, new CommonPacketPayload.Codec(), (payload, context) ->
|
||||
{
|
||||
ServerPlayerWrapper serverPlayer = Optional.of(context.player())
|
||||
.map(player -> player instanceof ServerPlayer ? (ServerPlayer) player : null)
|
||||
.map(ServerPlayerWrapper::getWrapper)
|
||||
.orElse(null);
|
||||
|
||||
if (payload.message() != null)
|
||||
{
|
||||
packetConsumer.accept(serverPlayer, payload.message());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPluginPacketClient(NetworkMessage message)
|
||||
{
|
||||
PacketDistributor.sendToServer(new CommonPacketPayload(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPluginPacketServer(ServerPlayer serverPlayer, NetworkMessage message)
|
||||
{
|
||||
PacketDistributor.sendToPlayer(serverPlayer, new CommonPacketPayload(message));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-35
@@ -3,20 +3,15 @@ package com.seibel.distanthorizons.neoforge;
|
||||
import com.seibel.distanthorizons.common.AbstractModInitializer;
|
||||
import com.seibel.distanthorizons.common.util.ProxyUtil;
|
||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.worldGeneration.BatchGenerationEnvironment;
|
||||
import com.seibel.distanthorizons.core.api.internal.ServerApi;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||
import net.neoforged.neoforge.event.level.ChunkEvent;
|
||||
import net.neoforged.neoforge.event.level.LevelEvent;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
@@ -128,26 +123,6 @@ public class NeoforgeServerProxy implements AbstractModInitializer.IEventProxy
|
||||
this.serverApi.serverChunkLoadEvent(chunk, levelWrapper);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void playerLoggedInEvent(PlayerEvent.PlayerLoggedInEvent event)
|
||||
{
|
||||
this.serverApi.serverPlayerJoinEvent(getServerPlayerWrapper(event));
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void playerLoggedOutEvent(PlayerEvent.PlayerLoggedOutEvent event)
|
||||
{
|
||||
this.serverApi.serverPlayerDisconnectEvent(getServerPlayerWrapper(event));
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void playerChangedDimensionEvent(PlayerEvent.PlayerChangedDimensionEvent event)
|
||||
{
|
||||
this.serverApi.serverPlayerLevelChangeEvent(
|
||||
getServerPlayerWrapper(event),
|
||||
getServerLevelWrapper(event.getFrom(), event),
|
||||
getServerLevelWrapper(event.getTo(), event)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
@@ -155,15 +130,6 @@ public class NeoforgeServerProxy implements AbstractModInitializer.IEventProxy
|
||||
//================//
|
||||
|
||||
private static ServerLevelWrapper getServerLevelWrapper(ServerLevel level) { return ServerLevelWrapper.getWrapper(level); }
|
||||
private static ServerLevelWrapper getServerLevelWrapper(ResourceKey<Level> resourceKey, PlayerEvent event)
|
||||
{
|
||||
//noinspection DataFlowIssue (possible NPE after getServer())
|
||||
return getServerLevelWrapper(event.getEntity().getServer().getLevel(resourceKey));
|
||||
}
|
||||
|
||||
private static ServerPlayerWrapper getServerPlayerWrapper(PlayerEvent event)
|
||||
{
|
||||
return ServerPlayerWrapper.getWrapper((ServerPlayer) event.getEntity());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-10
@@ -1,11 +1,8 @@
|
||||
package com.seibel.distanthorizons.neoforge.mixins.client;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
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;
|
||||
@@ -13,16 +10,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
@Mixin(ClientPacketListener.class)
|
||||
public class MixinClientPacketListener
|
||||
{
|
||||
@Shadow
|
||||
private ClientLevel level;
|
||||
// TODO update fabric version as well
|
||||
|
||||
@Inject(method = "handleLogin", at = @At("RETURN"))
|
||||
void onHandleLoginEnd(CallbackInfo ci)
|
||||
{
|
||||
ClientApi.INSTANCE.onClientOnlyConnected();
|
||||
ClientApi.INSTANCE.clientLevelLoadEvent(ClientLevelWrapper.getWrapper(this.level, true));
|
||||
}
|
||||
void onHandleLoginEnd(CallbackInfo ci) { ClientApi.INSTANCE.onClientOnlyConnected(); }
|
||||
|
||||
#if MC_VER < MC_1_19_4
|
||||
@Inject(method = "cleanup", at = @At("HEAD"))
|
||||
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Distant Horizons mod
|
||||
* licensed under the GNU LGPL v3 License.
|
||||
*
|
||||
* Copyright (C) 2020-2023 James Seibel
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.neoforge.mixins.server;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.IMixinServerPlayer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
#if MC_VER >= MC_1_21_1
|
||||
import net.minecraft.world.level.portal.DimensionTransition;
|
||||
#endif
|
||||
|
||||
|
||||
@Mixin(ServerPlayer.class)
|
||||
public class MixinServerPlayer implements IMixinServerPlayer
|
||||
{
|
||||
@Unique
|
||||
@Nullable
|
||||
private ServerLevel distantHorizons$dimensionChangeDestination;
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ServerLevel distantHorizons$getDimensionChangeDestination()
|
||||
{
|
||||
return this.distantHorizons$dimensionChangeDestination;
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "changeDimension")
|
||||
#if MC_VER >= MC_1_21_1
|
||||
public void changeDimension(DimensionTransition dimensionTransition, CallbackInfoReturnable<Entity> cir)
|
||||
{
|
||||
this.distantHorizons$dimensionChangeDestination = dimensionTransition.newLevel();
|
||||
}
|
||||
#else
|
||||
public void changeDimension(ServerLevel destination, CallbackInfoReturnable<Entity> cir)
|
||||
{
|
||||
this.distantHorizons$dimensionChangeDestination = destination;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MC_VER >= MC_1_20_1
|
||||
@Inject(at = @At("RETURN"), method = "setServerLevel")
|
||||
public void setServerLevel(ServerLevel level, CallbackInfo ci)
|
||||
#else
|
||||
@Inject(at = @At("RETURN"), method = "setLevel")
|
||||
public void setLevel(ServerLevel level, CallbackInfo ci)
|
||||
#endif
|
||||
{
|
||||
this.distantHorizons$dimensionChangeDestination = null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,8 +6,7 @@
|
||||
"server.MixinUtilBackgroundThread",
|
||||
"server.MixinChunkGenerator",
|
||||
"server.MixinTFChunkGenerator",
|
||||
"server.MixinChunkMap",
|
||||
"server.MixinServerPlayer"
|
||||
"server.MixinChunkMap"
|
||||
],
|
||||
"client": [
|
||||
"client.MixinClientPacketListener",
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
# Usage: .\verifyall.ps1 [forge|fabric|whatever to put before ":classes"]
|
||||
|
||||
param (
|
||||
[string]$prefix
|
||||
)
|
||||
|
||||
# Clear the screen
|
||||
Clear-Host
|
||||
|
||||
# Define an array to hold completed builds with color information
|
||||
$completedBuilds = @()
|
||||
|
||||
# Get all version properties files
|
||||
$versionFiles = Get-ChildItem -Path "./versionProperties/" -Filter "*.properties"
|
||||
|
||||
foreach ($versionFile in $versionFiles) {
|
||||
$version = [System.IO.Path]::GetFileNameWithoutExtension($versionFile.Name)
|
||||
|
||||
# Run the gradle command
|
||||
$gradleCommand = ".\gradlew $($prefix)classes -PmcVer=$version"
|
||||
$process = Start-Process -FilePath "cmd.exe" -ArgumentList "/c $gradleCommand" -NoNewWindow -PassThru -Wait
|
||||
|
||||
# Determine the result color
|
||||
if ($process.ExitCode -eq 0) {
|
||||
$color = "Green"
|
||||
} else {
|
||||
$color = "Red"
|
||||
}
|
||||
|
||||
# Print the result with formatting
|
||||
$versionLength = $version.Length
|
||||
$topChars = ("^" * $versionLength)
|
||||
$bottomChars = ("=" * $versionLength)
|
||||
|
||||
Write-Host "# $topChars" -ForegroundColor $color
|
||||
Write-Host "# $version" -ForegroundColor $color
|
||||
Write-Host "# $bottomChars" -ForegroundColor $color
|
||||
Write-Host
|
||||
|
||||
# Add result to completed builds with color
|
||||
$completedBuilds += @{ Version = $version; Color = $color }
|
||||
}
|
||||
|
||||
# Run clean and classes gradle tasks
|
||||
Start-Process -FilePath "cmd.exe" -ArgumentList "/c .\gradlew clean" -NoNewWindow -Wait
|
||||
Start-Process -FilePath "cmd.exe" -ArgumentList "/c .\gradlew classes" -NoNewWindow -Wait
|
||||
|
||||
# Print build results
|
||||
Write-Host
|
||||
Write-Host "Build results:"
|
||||
|
||||
foreach ($build in $completedBuilds) {
|
||||
Write-Host $build.Version -ForegroundColor $build.Color -NoNewline
|
||||
Write-Host " " -NoNewline # Add a space between versions
|
||||
}
|
||||
|
||||
Write-Host # End the line after all versions are printed
|
||||
@@ -1,43 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage: ./verifyall.sh [forge|fabric|whatever to put before ":classes"]
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
prefix="$1:"
|
||||
fi
|
||||
|
||||
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"
|
||||
echo -ne "\e[1;32m"
|
||||
else
|
||||
result+="\e[1;31m"
|
||||
echo -ne "\e[1;31m"
|
||||
fi
|
||||
result+=$version
|
||||
result+="\e[0m"
|
||||
|
||||
version_length=${#version}
|
||||
top_chars=$(printf '^%.0s' $(seq 1 $version_length))
|
||||
bottom_chars=$(printf '=%.0s' $(seq 1 $version_length))
|
||||
echo "# $top_chars"
|
||||
echo "# $version"
|
||||
echo "# $bottom_chars"
|
||||
echo -e "\e[0m"
|
||||
|
||||
completed_builds+=($result)
|
||||
done
|
||||
|
||||
./gradlew clean
|
||||
./gradlew classes
|
||||
|
||||
echo
|
||||
echo -e "\e[1mBuild results:\e[0m"
|
||||
echo -e "${completed_builds[*]}"
|
||||
@@ -7,9 +7,6 @@ accessWidenerVersion=1_16
|
||||
builds_for=fabric,forge
|
||||
embed_joml=true
|
||||
|
||||
# Netty
|
||||
netty_version=4.1.25.Final
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.14.24
|
||||
fabric_api_version=0.42.0+1.16
|
||||
|
||||
@@ -7,9 +7,6 @@ accessWidenerVersion=1_17
|
||||
builds_for=fabric,forge
|
||||
embed_joml=true
|
||||
|
||||
# Netty
|
||||
netty_version=4.1.25.Final
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.14.24
|
||||
fabric_api_version=0.46.1+1.17
|
||||
|
||||
@@ -7,9 +7,6 @@ accessWidenerVersion=1_18
|
||||
builds_for=fabric,forge
|
||||
embed_joml=true
|
||||
|
||||
# Netty
|
||||
netty_version=4.1.68.Final
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.14.24
|
||||
fabric_api_version=0.76.0+1.18.2
|
||||
|
||||
@@ -7,9 +7,6 @@ accessWidenerVersion=1_19_2
|
||||
builds_for=fabric,forge
|
||||
embed_joml=true
|
||||
|
||||
# Netty
|
||||
netty_version=4.1.77.Final
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.14.24
|
||||
fabric_api_version=0.76.1+1.19.2
|
||||
|
||||
@@ -6,9 +6,6 @@ compatible_minecraft_versions=["1.19.4"]
|
||||
accessWidenerVersion=1_19_4
|
||||
builds_for=fabric,forge
|
||||
|
||||
# Netty
|
||||
netty_version=4.1.82.Final
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.14.24
|
||||
fabric_api_version=0.87.1+1.19.4
|
||||
|
||||
@@ -6,9 +6,6 @@ compatible_minecraft_versions=["1.20", "1.20.1"]
|
||||
accessWidenerVersion=1_20
|
||||
builds_for=fabric,forge
|
||||
|
||||
# Netty
|
||||
netty_version=4.1.82.Final
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.15.6
|
||||
fabric_api_version=0.90.4+1.20.1
|
||||
|
||||
@@ -6,9 +6,6 @@ compatible_minecraft_versions=["1.20.2"]
|
||||
accessWidenerVersion=1_20_2
|
||||
builds_for=fabric,forge
|
||||
|
||||
# Netty
|
||||
netty_version=4.1.97.Final
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.15.6
|
||||
fabric_api_version=0.90.4+1.20.2
|
||||
|
||||
@@ -7,9 +7,6 @@ accessWidenerVersion=1_20_2
|
||||
builds_for=fabric,forge
|
||||
# neoforge can be added once the issue with mixins has been resolved
|
||||
|
||||
# Netty
|
||||
netty_version=4.1.97.Final
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.15.6
|
||||
fabric_api_version=0.91.2+1.20.4
|
||||
|
||||
@@ -7,9 +7,6 @@ accessWidenerVersion=1_20_6
|
||||
builds_for=fabric,neoforge
|
||||
# forge is broken due to gradle/build script issues
|
||||
|
||||
# Netty
|
||||
netty_version=4.1.97.Final
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.15.10
|
||||
fabric_api_version=0.97.8+1.20.6
|
||||
@@ -53,4 +50,4 @@ neoforge_version=20.6.70-beta
|
||||
# 2 = Can be referenced in code and runs in client
|
||||
enable_starlight_forge=0
|
||||
enable_terraforged=0
|
||||
enable_terrafirmacraft=0
|
||||
enable_terrafirmacraft=0
|
||||
|
||||
@@ -7,9 +7,6 @@ accessWidenerVersion=1_20_6
|
||||
builds_for=fabric,neoforge
|
||||
# forge is broken due to gradle/build script issues
|
||||
|
||||
# Netty
|
||||
netty_version=4.1.97.Final
|
||||
|
||||
# Fabric loader
|
||||
fabric_loader_version=0.15.11
|
||||
fabric_api_version=0.100.1+1.21
|
||||
@@ -53,4 +50,4 @@ neoforge_version=21.1.6
|
||||
# 2 = Can be referenced in code and runs in client
|
||||
enable_starlight_forge=0
|
||||
enable_terraforged=0
|
||||
enable_terrafirmacraft=0
|
||||
enable_terrafirmacraft=0
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
Remove-Item -Recurse -Force "run/client/Distant_Horizons_server_data"
|
||||
|
||||
Get-ChildItem -Path "run/server" -Recurse -Filter "Distant_Horizons" | ForEach-Object { Remove-Item -Recurse -Force $_.FullName }
|
||||
Get-ChildItem -Path "run/server" -Recurse -Filter "DistantHorizons.sqlite" | ForEach-Object { Remove-Item -Force $_.FullName }
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -rf run/client/Distant_Horizons_server_data
|
||||
rm -rf $(find run/server -name "Distant_Horizons")
|
||||
rm -rf $(find run/server -name "DistantHorizons.sqlite")
|
||||
Reference in New Issue
Block a user