Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a5b669245 |
+1
-6
@@ -24,18 +24,13 @@ variables:
|
||||
- .gradle
|
||||
- cache/
|
||||
allow_failure: true
|
||||
retry:
|
||||
max: 2
|
||||
when:
|
||||
- runner_system_failure
|
||||
- stuck_or_timeout_failure
|
||||
|
||||
|
||||
build:
|
||||
stage: build
|
||||
parallel:
|
||||
matrix:
|
||||
- MC_VER: ["1.16.5", "1.17.1", "1.18.2", "1.19.2", "1.19.4", "1.20.1", "1.20.2", "1.20.4", "1.20.6", "1.21.1"]
|
||||
- MC_VER: ["1.16.5", "1.17.1", "1.18.2", "1.19.2", "1.19.4", "1.20.1", "1.20.2", "1.20.4", "1.20.6", "1.21"]
|
||||
script:
|
||||
# this both runs the unit tests and assembles the code
|
||||
- ./gradlew clean -PmcVer="${MC_VER}" -PinfoGitCommit="${CI_COMMIT_SHA}" -PinfoGitBranch="${CI_COMMIT_BRANCH}" -PinfoBuildSource="GitLab CI (${CI_PIPELINE_ID})" --gradle-user-home cache/;
|
||||
|
||||
@@ -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>
|
||||
+3
-3
@@ -218,7 +218,8 @@ subprojects { p ->
|
||||
// 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}") {
|
||||
@@ -306,8 +307,7 @@ subprojects { p ->
|
||||
// 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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+3
-4
@@ -5,7 +5,6 @@
|
||||
|
||||
echo ==================== Note: All build jars will be in the folder called 'buildAllJars' ====================
|
||||
mkdir buildAllJars
|
||||
del buildAllJars/*
|
||||
|
||||
@rem Loop trough everything in the version properties folder
|
||||
for %%f in (versionProperties\*) do (
|
||||
@@ -14,11 +13,11 @@ for %%f in (versionProperties\*) do (
|
||||
|
||||
@rem Clean out the folders, build it, and merge it
|
||||
echo ==================== Cleaning workspace to build !version! ====================
|
||||
call .\gradlew.bat clean -PmcVer="!version!"
|
||||
call .\gradlew.bat clean -PmcVer="!version!" --no-daemon
|
||||
echo ==================== Building !version! ====================
|
||||
call .\gradlew.bat build -PmcVer="!version!"
|
||||
call .\gradlew.bat build -PmcVer="!version!" --no-daemon
|
||||
echo ==================== Merging !version! ====================
|
||||
call .\gradlew.bat mergeJars -PmcVer="!version!"
|
||||
call .\gradlew.bat mergeJars -PmcVer="!version!" --no-daemon
|
||||
echo ==================== Moving jar ====================
|
||||
move Merged\*.jar buildAllJars\
|
||||
)
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
// TODO can this be removed?
|
||||
//buildscript {
|
||||
// configurations.configureEach {
|
||||
// resolutionStrategy {
|
||||
// force 'org.spongepowered:vanillagradle:0.2.1-20240507.024226-82'
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
// temporary fix for broken spongepowered version
|
||||
buildscript {
|
||||
|
||||
+8
-165
@@ -1,28 +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.MinecraftServerWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.ServerPlayerWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftDedicatedServerWrapper;
|
||||
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.base.CodecCrashMessage;
|
||||
import com.seibel.distanthorizons.core.util.objects.Pair;
|
||||
import com.seibel.distanthorizons.core.world.DhServerWorld;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModAccessor;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IModChecker;
|
||||
import com.seibel.distanthorizons.coreapi.DependencyInjection.ApiEventInjector;
|
||||
@@ -33,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_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.
|
||||
@@ -93,7 +67,7 @@ public abstract class AbstractModInitializer
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
|
||||
|
||||
this.startup();
|
||||
this.logBuildInfo();
|
||||
this.printModInfo(true);
|
||||
|
||||
this.createClientProxy().registerEvents();
|
||||
this.createServerProxy(false).registerEvents();
|
||||
@@ -117,7 +91,7 @@ public abstract class AbstractModInitializer
|
||||
ApiEventInjector.INSTANCE.fireAllEvents(DhApiBeforeDhInitEvent.class, null);
|
||||
|
||||
this.startup();
|
||||
this.logBuildInfo();
|
||||
this.printModInfo(false);
|
||||
|
||||
// This prevents returning uninitialized Config values,
|
||||
// resulting from a circular reference mid-initialization in a static class
|
||||
@@ -126,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);
|
||||
|
||||
@@ -135,7 +107,7 @@ public abstract class AbstractModInitializer
|
||||
|
||||
this.subscribeServerStartingEvent(server ->
|
||||
{
|
||||
MinecraftServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer)server;
|
||||
MinecraftDedicatedServerWrapper.INSTANCE.dedicatedServer = (DedicatedServer)server;
|
||||
|
||||
this.initConfig();
|
||||
this.postInit();
|
||||
@@ -158,13 +130,13 @@ public abstract class AbstractModInitializer
|
||||
this.createInitialBindings();
|
||||
}
|
||||
|
||||
private void logBuildInfo()
|
||||
private void printModInfo(boolean printGitInfo)
|
||||
{
|
||||
LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION);
|
||||
|
||||
// if the build is stable the branch/commit/etc shouldn't be needed
|
||||
if (ModInfo.IS_DEV_BUILD)
|
||||
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);
|
||||
@@ -194,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) -> (commandContext) -> {
|
||||
Object value = getter.apply(commandContext);
|
||||
|
||||
commandContext.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((commandContext) -> {
|
||||
#if MC_VER >= MC_1_20_1
|
||||
commandContext.getSource().sendSuccess(() -> Component.literal("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
|
||||
#elif MC_VER >= MC_1_19_2
|
||||
commandContext.getSource().sendSuccess(Component.literal("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true);
|
||||
#else // < 1.19.2
|
||||
commandContext.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_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
|
||||
.networkSession.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
|
||||
.networkSession.sendMessage(new CodecCrashMessage(CodecCrashMessage.ECrashPhase.DECODE));
|
||||
return 1;
|
||||
}));
|
||||
this.commandDispatcher.register(dhcrash);
|
||||
}
|
||||
}
|
||||
private void initCommands() { /* currently unimplemented */ }
|
||||
|
||||
|
||||
|
||||
|
||||
-113
@@ -1,113 +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.IncompatibleMessageInternalEvent;
|
||||
import com.seibel.distanthorizons.core.network.event.internal.ProtocolErrorInternalEvent;
|
||||
import com.seibel.distanthorizons.core.network.messages.MessageRegistry;
|
||||
import com.seibel.distanthorizons.core.network.messages.AbstractNetworkMessage;
|
||||
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 sendToClient(IServerPlayerWrapper serverPlayer, AbstractNetworkMessage message)
|
||||
{
|
||||
this.sendToClient((ServerPlayer) serverPlayer.getWrappedMcObject(), message);
|
||||
}
|
||||
public abstract void sendToClient(ServerPlayer serverPlayer, AbstractNetworkMessage message);
|
||||
|
||||
@Override
|
||||
public abstract void sendToServer(AbstractNetworkMessage message);
|
||||
|
||||
public static AbstractNetworkMessage decodeMessage(FriendlyByteBuf in)
|
||||
{
|
||||
AbstractNetworkMessage message = null;
|
||||
|
||||
try
|
||||
{
|
||||
in.markReaderIndex();
|
||||
|
||||
int protocolVersion = in.readShort();
|
||||
if (protocolVersion != ModInfo.PROTOCOL_VERSION)
|
||||
{
|
||||
return new IncompatibleMessageInternalEvent(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 ProtocolErrorInternalEvent(e, message, true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Prevent connection crashing if not entire buffer has been read
|
||||
in.readerIndex(in.writerIndex());
|
||||
}
|
||||
}
|
||||
|
||||
public static void encodeMessage(FriendlyByteBuf out, AbstractNetworkMessage 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 ProtocolErrorInternalEvent(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,36 +0,0 @@
|
||||
package com.seibel.distanthorizons.common;
|
||||
|
||||
#if MC_VER >= MC_1_20_6
|
||||
|
||||
import com.seibel.distanthorizons.core.network.messages.AbstractNetworkMessage;
|
||||
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 AbstractNetworkMessage 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
|
||||
-85
@@ -1,85 +0,0 @@
|
||||
package com.seibel.distanthorizons.common.commonMixins;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.api.internal.ServerApi;
|
||||
import com.seibel.distanthorizons.core.api.internal.SharedApi;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
public class MixinChunkMapCommon
|
||||
{
|
||||
|
||||
public static void onChunkSave(ServerLevel level, ChunkAccess chunk, CallbackInfoReturnable<Boolean> ci)
|
||||
{
|
||||
// is this position already being updated?
|
||||
if (SharedApi.isChunkAtChunkPosAlreadyUpdating(chunk.getPos().x, chunk.getPos().z))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// is this chunk being saved to disk?
|
||||
boolean savingChunkToDisk = ci.getReturnValue();
|
||||
// true means a chunk was saved to disk
|
||||
if (!savingChunkToDisk)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO are the following validations necessary since we are checking above if
|
||||
// the callback return value should state if the chunk was actually saved or not?
|
||||
// Do we trust it to always be correct?
|
||||
|
||||
|
||||
|
||||
// corrupt/incomplete chunk validation //
|
||||
|
||||
// MC has a tendency to try saving incomplete or corrupted chunks (which show up as empty or black chunks)
|
||||
// this logic should prevent that from happening
|
||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
||||
if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect())
|
||||
{
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (chunk.isUnsaved() || chunk.isUpgrading() || !chunk.isLightCorrect())
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// biome validation //
|
||||
|
||||
// some chunks may be missing their biomes, which cause issues when attempting to save them
|
||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
||||
if (chunk.getBiomes() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#else
|
||||
try
|
||||
{
|
||||
// this will throw an exception if the biomes aren't set up
|
||||
chunk.getNoiseBiome(0,0,0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// submit the update event
|
||||
ServerApi.INSTANCE.serverChunkSaveEvent(
|
||||
new ChunkWrapper(chunk, level, ServerLevelWrapper.getWrapper(level)),
|
||||
ServerLevelWrapper.getWrapper(level)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.seibel.distanthorizons.forge.mixins.client;
|
||||
package com.seibel.distanthorizons.common.mixins.client;
|
||||
|
||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||
import net.minecraft.client.gui.components.DebugScreenOverlay;
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.fabric.mixins.client;
|
||||
package com.seibel.distanthorizons.common.mixins.client;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.seibel.distanthorizons.fabric.mixins.client;
|
||||
package com.seibel.distanthorizons.common.mixins.client;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.DependencySetupDoneCheck;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.seibel.distanthorizons.fabric.mixins.client;
|
||||
package com.seibel.distanthorizons.common.mixins.client;
|
||||
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
+2
-2
@@ -22,7 +22,7 @@ package com.seibel.distanthorizons.common.wrappers;
|
||||
import com.seibel.distanthorizons.common.wrappers.gui.ClassicConfigGUI;
|
||||
import com.seibel.distanthorizons.common.wrappers.gui.LangWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.level.KeyedClientLevelManager;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftServerWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftDedicatedServerWrapper;
|
||||
import com.seibel.distanthorizons.core.level.IKeyedClientLevelManager;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.config.IConfigGui;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.config.ILangWrapper;
|
||||
@@ -60,7 +60,7 @@ public class DependencySetup
|
||||
//@Environment(EnvType.SERVER)
|
||||
public static void createServerBindings()
|
||||
{
|
||||
SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftServerWrapper.INSTANCE);
|
||||
SingletonInjector.INSTANCE.bind(IMinecraftSharedWrapper.class, MinecraftDedicatedServerWrapper.INSTANCE);
|
||||
}
|
||||
|
||||
//@Environment(EnvType.CLIENT)
|
||||
|
||||
+38
-5
@@ -20,9 +20,11 @@
|
||||
package com.seibel.distanthorizons.common.wrappers;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.seibel.distanthorizons.core.enums.EDhDirection;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||
|
||||
@@ -135,10 +137,41 @@ public class McObjectConverter
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockPos Convert(DhBlockPos wrappedPos) { return new BlockPos(wrappedPos.getX(), wrappedPos.getY(), wrappedPos.getZ()); }
|
||||
public static ChunkPos Convert(DhChunkPos wrappedPos) { return new ChunkPos(wrappedPos.getX(), wrappedPos.getZ()); }
|
||||
public static BlockPos Convert(DhBlockPos wrappedPos)
|
||||
{
|
||||
return new BlockPos(wrappedPos.x, wrappedPos.y, wrappedPos.z);
|
||||
}
|
||||
public static ChunkPos Convert(DhChunkPos wrappedPos)
|
||||
{
|
||||
return new ChunkPos(wrappedPos.x, wrappedPos.z);
|
||||
}
|
||||
|
||||
public static Direction Convert(EDhDirection lodDirection) { return directions[lodDirection.ordinal()]; }
|
||||
public static EDhDirection Convert(Direction direction) { return lodDirections[direction.ordinal()]; }
|
||||
public static Direction Convert(EDhDirection lodDirection)
|
||||
{
|
||||
return directions[lodDirection.ordinal()];
|
||||
}
|
||||
public static EDhDirection Convert(Direction direction)
|
||||
{
|
||||
return lodDirections[direction.ordinal()];
|
||||
}
|
||||
public static void DebugCheckAllPackers()
|
||||
{
|
||||
BiConsumer<Integer, Integer> func = (x, z) -> DhChunkPos._DebugCheckPacker(x, z, ChunkPos.asLong(x, z));
|
||||
func.accept(0, 0);
|
||||
func.accept(12345, 134);
|
||||
func.accept(-12345, -134);
|
||||
func.accept(-30000000 / 16, 30000000 / 16);
|
||||
func.accept(30000000 / 16, -30000000 / 16);
|
||||
func.accept(30000000 / 16, 30000000 / 16);
|
||||
func.accept(-30000000 / 16, -30000000 / 16);
|
||||
Consumer<BlockPos> func2 = (p) -> DhBlockPos._DebugCheckPacker(p.getX(), p.getY(), p.getZ(), p.asLong());
|
||||
func2.accept(new BlockPos(0, 0, 0));
|
||||
func2.accept(new BlockPos(12345, 134, 123));
|
||||
func2.accept(new BlockPos(-12345, -134, -80));
|
||||
func2.accept(new BlockPos(-30000000, 2047, 30000000));
|
||||
func2.accept(new BlockPos(30000000, -2048, -30000000));
|
||||
func2.accept(new BlockPos(30000000, 2047, 30000000));
|
||||
func2.accept(new BlockPos(-30000000, -2048, -30000000));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+47
-13
@@ -155,7 +155,7 @@ public class WrapperFactory implements IWrapperFactory
|
||||
}
|
||||
}
|
||||
|
||||
//#if MC_VER <= MC_1_XX_X
|
||||
#if MC_VER <= MC_1_21
|
||||
else if (objectArray.length == 2)
|
||||
{
|
||||
// correct number of parameters from the API
|
||||
@@ -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);
|
||||
@@ -191,7 +201,16 @@ public class WrapperFactory implements IWrapperFactory
|
||||
{
|
||||
throw new ClassCastException(createChunkWrapperErrorMessage(objectArray));
|
||||
}
|
||||
//#endif
|
||||
#else
|
||||
// Intentional compiler error to bring attention to the missing wrapper function.
|
||||
// If you need to work on an unimplemented version but don't have the ability to implement this yet
|
||||
// you can comment it out, but please don't commit it. Someone will have to implement it.
|
||||
|
||||
// After implementing the new version please read this method's javadocs for instructions
|
||||
// on what other locations also need to be updated, the DhAPI specifically needs to
|
||||
// be updated to state which objects this method accepts.
|
||||
not implemented for this version of Minecraft!
|
||||
#endif
|
||||
}
|
||||
/**
|
||||
* Note: when this is updated for different MC versions,
|
||||
@@ -201,13 +220,16 @@ public class WrapperFactory implements IWrapperFactory
|
||||
{
|
||||
String[] expectedClassNames;
|
||||
|
||||
//#if MC_VER <= MC_1_XX_X
|
||||
#if MC_VER <= MC_1_21
|
||||
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
|
||||
#else
|
||||
// See preprocessor comment in createChunkWrapper() for full documentation
|
||||
not implemented for this version of Minecraft!
|
||||
#endif
|
||||
|
||||
return createWrapperErrorMessage("Chunk wrapper", expectedClassNames, objectArray);
|
||||
}
|
||||
@@ -246,7 +268,7 @@ public class WrapperFactory implements IWrapperFactory
|
||||
|
||||
Biome biome = (Biome) objectArray[0];
|
||||
return BiomeWrapper.getBiomeWrapper(biome, coreLevelWrapper);
|
||||
#else
|
||||
#elif MC_VER <= MC_1_21
|
||||
if (!(objectArray[0] instanceof Holder) || !(((Holder<?>) objectArray[0]).value() instanceof Biome))
|
||||
{
|
||||
throw new ClassCastException(createBiomeWrapperErrorMessage(objectArray));
|
||||
@@ -254,6 +276,9 @@ public class WrapperFactory implements IWrapperFactory
|
||||
|
||||
Holder<Biome> biomeHolder = (Holder<Biome>) objectArray[0];
|
||||
return BiomeWrapper.getBiomeWrapper(biomeHolder, coreLevelWrapper);
|
||||
#else
|
||||
// See preprocessor comment in createChunkWrapper() for full documentation (not a typo, check createChunkWrapper()'s else statement for full documentation)
|
||||
not implemented for this version of Minecraft!
|
||||
#endif
|
||||
}
|
||||
/**
|
||||
@@ -266,8 +291,11 @@ public class WrapperFactory implements IWrapperFactory
|
||||
|
||||
#if MC_VER < MC_1_18_2
|
||||
expectedClassNames = new String[] { Biome.class.getName() };
|
||||
#else
|
||||
#elif MC_VER <= MC_1_21
|
||||
expectedClassNames = new String[] { Holder.class.getName()+"<"+Biome.class.getName()+">" };
|
||||
#else
|
||||
// See preprocessor comment in createChunkWrapper() for full documentation
|
||||
not implemented for this version of Minecraft!
|
||||
#endif
|
||||
|
||||
return createWrapperErrorMessage("Biome wrapper", expectedClassNames, objectArray);
|
||||
@@ -284,7 +312,7 @@ public class WrapperFactory implements IWrapperFactory
|
||||
|
||||
|
||||
|
||||
//#if MC_VER <= MC_1_XX_X
|
||||
#if MC_VER <= MC_1_21
|
||||
if (objectArray.length != 1)
|
||||
{
|
||||
throw new ClassCastException(createBlockStateWrapperErrorMessage(objectArray));
|
||||
@@ -296,7 +324,10 @@ public class WrapperFactory implements IWrapperFactory
|
||||
|
||||
BlockState blockState = (BlockState) objectArray[0];
|
||||
return BlockStateWrapper.fromBlockState(blockState, coreLevelWrapper);
|
||||
//#endif
|
||||
#else
|
||||
// See preprocessor comment in createChunkWrapper() for full documentation (not a typo, check createChunkWrapper()'s else statement for full documentation)
|
||||
not implemented for this version of Minecraft!
|
||||
#endif
|
||||
}
|
||||
/**
|
||||
* Note: when this is updated for different MC versions,
|
||||
@@ -308,8 +339,11 @@ public class WrapperFactory implements IWrapperFactory
|
||||
|
||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
||||
expectedClassNames = new String[] { Biome.class.getName() };
|
||||
#else
|
||||
#elif MC_VER <= MC_1_21
|
||||
expectedClassNames = new String[] { Holder.class.getName()+"<"+Biome.class.getName()+">" };
|
||||
#else
|
||||
// See preprocessor comment in createChunkWrapper() for full documentation
|
||||
not implemented for this version of Minecraft!
|
||||
#endif
|
||||
|
||||
return createWrapperErrorMessage("BlockState wrapper", expectedClassNames, objectArray);
|
||||
|
||||
+1
-1
@@ -293,7 +293,7 @@ public class BiomeWrapper implements IBiomeWrapper
|
||||
ResourceLocation resourceLocation;
|
||||
try
|
||||
{
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
resourceLocation = new ResourceLocation(resourceLocationString.substring(0, separatorIndex), resourceLocationString.substring(separatorIndex + 1));
|
||||
#else
|
||||
resourceLocation = ResourceLocation.fromNamespaceAndPath(resourceLocationString.substring(0, separatorIndex), resourceLocationString.substring(separatorIndex + 1));
|
||||
|
||||
+9
-53
@@ -30,7 +30,6 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrappe
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.level.block.BeaconBeamBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
@@ -54,6 +53,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;
|
||||
@@ -102,9 +102,8 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
private byte blockMaterialId = 0;
|
||||
|
||||
private final boolean isBeaconBlock;
|
||||
private final boolean isBeaconBaseBlock;
|
||||
/** null if this block can't tint beacons */
|
||||
private final Color beaconTintColor;
|
||||
private final boolean isBeaconBaseBlock;
|
||||
private final boolean isGlassBlock;
|
||||
private final Color mapColor;
|
||||
|
||||
|
||||
@@ -133,26 +132,6 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be faster than {@link BlockStateWrapper#fromBlockState(BlockState, ILevelWrapper)}
|
||||
* in cases where the same block state is expected to be referenced multiple times.
|
||||
*/
|
||||
public static BlockStateWrapper fromBlockState(BlockState blockState, ILevelWrapper levelWrapper, IBlockStateWrapper guess)
|
||||
{
|
||||
BlockState guessBlockState = (guess == null || guess.isAir()) ? null : (BlockState) guess.getWrappedMcObject();
|
||||
BlockState inputBlockState = (blockState == null || blockState.isAir()) ? null : blockState;
|
||||
|
||||
if (guess instanceof BlockStateWrapper guessWrapper
|
||||
&& guessBlockState == inputBlockState)
|
||||
{
|
||||
return guessWrapper;
|
||||
}
|
||||
else
|
||||
{
|
||||
return fromBlockState(blockState, levelWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
private BlockStateWrapper(BlockState blockState, ILevelWrapper levelWrapper)
|
||||
{
|
||||
this.blockState = blockState;
|
||||
@@ -160,7 +139,6 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
this.hashCode = Objects.hash(this.serialString);
|
||||
this.blockMaterialId = this.calculateEDhApiBlockMaterialId().index;
|
||||
|
||||
// beacon blocks
|
||||
String lowercaseSerial = this.serialString.toLowerCase();
|
||||
boolean isBeaconBaseBlock = false;
|
||||
for (int i = 0; i < LodUtil.BEACON_BASE_BLOCK_NAME_LIST.size(); i++)
|
||||
@@ -174,28 +152,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
}
|
||||
this.isBeaconBaseBlock = isBeaconBaseBlock;
|
||||
this.isBeaconBlock = lowercaseSerial.contains("minecraft:beacon");
|
||||
|
||||
// beacon tint color
|
||||
Color beaconTintColor = null;
|
||||
if (this.blockState != null
|
||||
// beacon blocks also show up here, but since they block the beacon beam we don't want their color
|
||||
&& !this.isBeaconBlock)
|
||||
{
|
||||
Block block = this.blockState.getBlock();
|
||||
if (block instanceof BeaconBeamBlock)
|
||||
{
|
||||
int colorInt;
|
||||
#if MC_VER <= MC_1_19_4
|
||||
colorInt = ((BeaconBeamBlock) block).getColor().getMaterialColor().col;
|
||||
#else
|
||||
colorInt = ((BeaconBeamBlock) block).getColor().getMapColor().col;
|
||||
#endif
|
||||
|
||||
beaconTintColor = ColorUtil.toColorObjRGB(colorInt);
|
||||
}
|
||||
}
|
||||
this.beaconTintColor = beaconTintColor;
|
||||
|
||||
this.isGlassBlock = lowercaseSerial.contains("glass");
|
||||
|
||||
int mcColor = 0;
|
||||
if (this.blockState != null)
|
||||
@@ -442,12 +399,10 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
@Override
|
||||
public boolean isBeaconBaseBlock() { return this.isBeaconBaseBlock; }
|
||||
@Override
|
||||
public boolean isBeaconTintBlock() { return this.beaconTintColor != null; }
|
||||
public boolean isGlassBlock() { return this.isGlassBlock; }
|
||||
|
||||
@Override
|
||||
public Color getMapColor() { return this.mapColor; }
|
||||
@Override
|
||||
public Color getBeaconTintColor() { return this.beaconTintColor; }
|
||||
|
||||
@Override
|
||||
public byte getMaterialId() { return this.blockMaterialId; }
|
||||
@@ -543,7 +498,7 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
ResourceLocation resourceLocation;
|
||||
try
|
||||
{
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
resourceLocation = new ResourceLocation(resourceStateString.substring(0, separatorIndex), resourceStateString.substring(separatorIndex + 1));
|
||||
#else
|
||||
resourceLocation = ResourceLocation.fromNamespaceAndPath(resourceStateString.substring(0, separatorIndex), resourceStateString.substring(separatorIndex + 1));
|
||||
@@ -561,8 +516,9 @@ public class BlockStateWrapper implements IBlockStateWrapper
|
||||
{
|
||||
|
||||
#if MC_VER > MC_1_17_1
|
||||
LodUtil.assertTrue(levelWrapper != null && levelWrapper.getWrappedMcObject() != null);
|
||||
Level level = (Level)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;
|
||||
|
||||
+5
-1
@@ -19,9 +19,13 @@
|
||||
|
||||
package com.seibel.distanthorizons.common.wrappers.block;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.block.BiomeWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.block.TextureAtlasSpriteWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.block.TintWithoutLevelOverrider;
|
||||
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
||||
import com.seibel.distanthorizons.common.wrappers.block.*;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
+161
-44
@@ -21,18 +21,13 @@ 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.misc.MutableBlockPosWrapper;
|
||||
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.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;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IMutableBlockPosWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
@@ -89,7 +84,6 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
|
||||
/** can be used for interactions with the underlying chunk where creating new BlockPos objects could cause issues for the garbage collector. */
|
||||
private static final ThreadLocal<BlockPos.MutableBlockPos> MUTABLE_BLOCK_POS_REF = ThreadLocal.withInitial(() -> new BlockPos.MutableBlockPos());
|
||||
private static final ThreadLocal<MutableBlockPosWrapper> MUTABLE_BLOCK_POS_WRAPPER_REF = ThreadLocal.withInitial(() -> new MutableBlockPosWrapper());
|
||||
|
||||
|
||||
private final ChunkAccess chunk;
|
||||
@@ -97,8 +91,7 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
private final LevelReader lightSource;
|
||||
private final ILevelWrapper wrappedLevel;
|
||||
|
||||
private boolean isDhBlockLightCorrect = false;
|
||||
private boolean isDhSkyLightCorrect = false;
|
||||
private boolean isDhLightCorrect = false;
|
||||
/** only used when connected to a dedicated server */
|
||||
private boolean isMcClientLightingCorrect = false;
|
||||
|
||||
@@ -107,9 +100,26 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
|
||||
private ArrayList<DhBlockPos> blockLightPosList = null;
|
||||
|
||||
private boolean useDhLighting;
|
||||
|
||||
private int minNonEmptyHeight = Integer.MIN_VALUE;
|
||||
private int maxNonEmptyHeight = Integer.MAX_VALUE;
|
||||
|
||||
private int blockBiomeHashCode = 0;
|
||||
|
||||
/**
|
||||
* Due to vanilla `isClientLightReady()` not being designed for use by a non-render thread, it may return 'true'
|
||||
* before the light engine has ticked, (right after all light changes is marked by the engine to be processed).
|
||||
* To fix this, on client-only mode, we mixin-redirect the `isClientLightReady()` so that after the call, it will
|
||||
* trigger a synchronous update of this flag here on all chunks that are wrapped. <br><br>
|
||||
*
|
||||
* Note: Using a static weak hash map to store the chunks that need to be updated, as instance of chunk wrapper
|
||||
* can be duplicated, with same chunk instance. And the data stored here are all temporary, and thus will not be
|
||||
* visible when a chunk is re-wrapped later. <br>
|
||||
* (Also, thread safety done via a reader writer lock)
|
||||
*/
|
||||
private static final ConcurrentLinkedQueue<ChunkWrapper> chunksNeedingClientLightUpdating = new ConcurrentLinkedQueue<>();
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
@@ -123,6 +133,14 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
this.wrappedLevel = wrappedLevel;
|
||||
this.chunkPos = new DhChunkPos(chunk.getPos().x, chunk.getPos().z);
|
||||
|
||||
// TODO is this the best way to differentiate between when we are generating chunks and when MC gave us a chunk?
|
||||
boolean isDhGeneratedChunk = (this.lightSource.getClass() == DhLitWorldGenRegion.class);
|
||||
// MC loaded chunks should get their lighting from MC, DH generated chunks should get their lighting from DH
|
||||
this.useDhLighting = isDhGeneratedChunk;
|
||||
|
||||
// FIXME +1 is to handle the fact that LodDataBuilder adds +1 to all block lighting calculations, also done in the relative position validator
|
||||
|
||||
chunksNeedingClientLightUpdating.add(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -279,22 +297,6 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
return BlockStateWrapper.fromBlockState(this.chunk.getBlockState(blockPos), this.wrappedLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockStateWrapper getBlockState(int relX, int relY, int relZ, IMutableBlockPosWrapper mcBlockPos, IBlockStateWrapper guess)
|
||||
{
|
||||
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, relY, relZ);
|
||||
|
||||
BlockPos.MutableBlockPos pos = (BlockPos.MutableBlockPos)mcBlockPos.getWrappedMcObject();
|
||||
pos.setX(relX);
|
||||
pos.setY(relY);
|
||||
pos.setZ(relZ);
|
||||
|
||||
return BlockStateWrapper.fromBlockState(this.chunk.getBlockState(pos), this.wrappedLevel, guess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMutableBlockPosWrapper getMutableBlockPosWrapper() { return MUTABLE_BLOCK_POS_WRAPPER_REF.get(); }
|
||||
|
||||
@Override
|
||||
public DhChunkPos getChunkPos() { return this.chunkPos; }
|
||||
|
||||
@@ -303,7 +305,7 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
public ChunkStatus getStatus() { return getStatus(this.getChunk()); }
|
||||
public static ChunkStatus getStatus(ChunkAccess chunk)
|
||||
{
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
return chunk.getStatus();
|
||||
#else
|
||||
return chunk.getPersistedStatus();
|
||||
@@ -325,15 +327,45 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
// lighting //
|
||||
//==========//
|
||||
|
||||
@Override
|
||||
public void setIsDhSkyLightCorrect(boolean isDhLightCorrect) { this.isDhSkyLightCorrect = isDhLightCorrect; }
|
||||
@Override
|
||||
public void setIsDhBlockLightCorrect(boolean isDhLightCorrect) { this.isDhBlockLightCorrect = isDhLightCorrect; }
|
||||
@Override
|
||||
public void setIsDhLightCorrect(boolean isDhLightCorrect) { this.isDhLightCorrect = isDhLightCorrect; }
|
||||
|
||||
@Override
|
||||
public boolean isDhBlockLightingCorrect() { return this.isDhBlockLightCorrect; }
|
||||
public void setUseDhLighting(boolean useDhLighting) { this.useDhLighting = useDhLighting; }
|
||||
|
||||
@Override
|
||||
public boolean isDhSkyLightCorrect() { return this.isDhSkyLightCorrect; }
|
||||
public boolean isLightCorrect()
|
||||
{
|
||||
if (this.useDhLighting)
|
||||
{
|
||||
return this.isDhLightCorrect;
|
||||
}
|
||||
|
||||
|
||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
||||
return false; // MC's lighting engine doesn't work consistently enough to trust for 1.16 or 1.17
|
||||
#else
|
||||
if (this.chunk instanceof LevelChunk)
|
||||
{
|
||||
LevelChunk levelChunk = (LevelChunk) this.chunk;
|
||||
if (levelChunk.getLevel() instanceof ClientLevel)
|
||||
{
|
||||
// connected to a server
|
||||
return this.isMcClientLightingCorrect;
|
||||
}
|
||||
else
|
||||
{
|
||||
// in a single player world
|
||||
return this.chunk.isLightCorrect() && levelChunk.loaded;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// called when in a single player world and the chunk is a proto chunk (in world gen, and not active)
|
||||
return this.chunk.isLightCorrect();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@@ -358,8 +390,6 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
return this.blockLightStorage;
|
||||
}
|
||||
public void setBlockLightStorage(ChunkLightStorage lightStorage) { this.blockLightStorage = lightStorage; }
|
||||
@Override
|
||||
public void clearDhBlockLighting() { this.getBlockLightStorage().clear(); }
|
||||
|
||||
|
||||
@Override
|
||||
@@ -374,8 +404,6 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, y, relZ);
|
||||
this.getSkyLightStorage().set(relX, y, relZ, lightValue);
|
||||
}
|
||||
@Override
|
||||
public void clearDhSkyLighting() { this.getSkyLightStorage().clear(); }
|
||||
|
||||
private ChunkLightStorage getSkyLightStorage()
|
||||
{
|
||||
@@ -388,12 +416,50 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
public void setSkyLightStorage(ChunkLightStorage lightStorage) { this.skyLightStorage = lightStorage; }
|
||||
|
||||
|
||||
@Override
|
||||
public int getBlockLight(int relX, int y, int relZ)
|
||||
{
|
||||
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, y, relZ);
|
||||
|
||||
// use the full lighting engine when the chunks are within render distance or the config requests it
|
||||
if (this.useDhLighting)
|
||||
{
|
||||
// DH lighting method
|
||||
return this.getBlockLightStorage().get(relX, y, relZ);
|
||||
}
|
||||
else
|
||||
{
|
||||
// note: this returns 0 if the chunk is unload
|
||||
|
||||
// MC lighting method
|
||||
return this.lightSource.getBrightness(LightLayer.BLOCK, new BlockPos(relX + this.getMinBlockX(), y, relZ + this.getMinBlockZ()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkyLight(int relX, int y, int relZ)
|
||||
{
|
||||
this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, y, relZ);
|
||||
|
||||
// use the full lighting engine when the chunks are within render distance or the config requests it
|
||||
if (this.useDhLighting)
|
||||
{
|
||||
// DH lighting method
|
||||
return this.getSkyLightStorage().get(relX, y, relZ);
|
||||
}
|
||||
else
|
||||
{
|
||||
// MC lighting method
|
||||
return this.lightSource.getBrightness(LightLayer.SKY, new BlockPos(relX + this.getMinBlockX(), y, relZ + this.getMinBlockZ()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME synchronized is necessary for a rare issue where this method is called from two separate threads at the same time
|
||||
* before the list has finished populating.
|
||||
*/
|
||||
@Override
|
||||
public synchronized ArrayList<DhBlockPos> getWorldBlockLightPosList()
|
||||
public synchronized ArrayList<DhBlockPos> getBlockLightPosList()
|
||||
{
|
||||
// only populate the list once
|
||||
if (this.blockLightPosList == null)
|
||||
@@ -409,13 +475,7 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
#else
|
||||
this.chunk.findBlockLightSources((blockPos, blockState) ->
|
||||
{
|
||||
DhBlockPos pos = new DhBlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ());
|
||||
|
||||
// this can be uncommented if MC decides to return relative block positions in the future instead of world positions
|
||||
//pos.mutateToChunkRelativePos(pos);
|
||||
//pos.mutateOffset(this.chunkPos.getMinBlockX(), 0, this.chunkPos.getMinBlockZ(), pos);
|
||||
|
||||
this.blockLightPosList.add(pos);
|
||||
this.blockLightPosList.add(new DhBlockPos(blockPos.getX(), blockPos.getY(), blockPos.getZ()));
|
||||
});
|
||||
#endif
|
||||
}
|
||||
@@ -423,6 +483,63 @@ public class ChunkWrapper implements IChunkWrapper
|
||||
return this.blockLightPosList;
|
||||
}
|
||||
|
||||
public static void syncedUpdateClientLightStatus()
|
||||
{
|
||||
#if MC_VER < MC_1_18_2
|
||||
// TODO: Check what to do in 1.18.1 and older
|
||||
|
||||
// since we don't currently handle this list,
|
||||
// clear it to prevent memory leaks
|
||||
chunksNeedingClientLightUpdating.clear();
|
||||
|
||||
#else
|
||||
|
||||
// update the chunks client lighting
|
||||
ChunkWrapper chunkWrapper = chunksNeedingClientLightUpdating.poll();
|
||||
while (chunkWrapper != null)
|
||||
{
|
||||
chunkWrapper.updateIsClientLightingCorrect();
|
||||
chunkWrapper = chunksNeedingClientLightUpdating.poll();
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
/** Should be called after client light updates are triggered. */
|
||||
private void updateIsClientLightingCorrect()
|
||||
{
|
||||
if (this.chunk instanceof LevelChunk && ((LevelChunk) this.chunk).getLevel() instanceof ClientLevel)
|
||||
{
|
||||
LevelChunk levelChunk = (LevelChunk) this.chunk;
|
||||
ClientChunkCache clientChunkCache = ((ClientLevel) levelChunk.getLevel()).getChunkSource();
|
||||
this.isMcClientLightingCorrect = clientChunkCache.getChunkForLighting(this.chunk.getPos().x, this.chunk.getPos().z) != null &&
|
||||
#if MC_VER <= MC_1_17_1
|
||||
levelChunk.isLightCorrect();
|
||||
#elif MC_VER < MC_1_20_1
|
||||
levelChunk.isClientLightReady();
|
||||
#else
|
||||
checkLightSectionsOnChunk(levelChunk, levelChunk.getLevel().getLightEngine());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if MC_VER >= MC_1_20_1
|
||||
private static boolean checkLightSectionsOnChunk(LevelChunk chunk, LevelLightEngine engine)
|
||||
{
|
||||
LevelChunkSection[] sections = chunk.getSections();
|
||||
int minY = chunk.getMinSection();
|
||||
int maxY = chunk.getMaxSection();
|
||||
for (int y = minY; y < maxY; ++y)
|
||||
{
|
||||
LevelChunkSection section = sections[chunk.getSectionIndexFromSectionY(y)];
|
||||
if (section.hasOnlyAir()) continue;
|
||||
if (!engine.lightOnInSection(SectionPos.of(chunk.getPos(), y)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
|
||||
+1
-1
@@ -259,7 +259,7 @@ public class ClassicConfigGUI
|
||||
0, 0,
|
||||
// Some textuary stuff
|
||||
0,
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
new ResourceLocation(ModInfo.ID, "textures/gui/changelog.png"),
|
||||
#else
|
||||
ResourceLocation.fromNamespaceAndPath(ModInfo.ID, "textures/gui/changelog.png"),
|
||||
|
||||
+2
-2
@@ -76,7 +76,7 @@ public class UpdateModScreen extends DhScreen
|
||||
0, 0,
|
||||
// Some textuary stuff
|
||||
0,
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
new ResourceLocation(ModInfo.ID, "logo.png"),
|
||||
#else
|
||||
ResourceLocation.fromNamespaceAndPath(ModInfo.ID, "logo.png"),
|
||||
@@ -107,7 +107,7 @@ public class UpdateModScreen extends DhScreen
|
||||
0, 0,
|
||||
// Some textuary stuff
|
||||
0,
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
new ResourceLocation(ModInfo.ID, "textures/gui/changelog.png"),
|
||||
#else
|
||||
ResourceLocation.fromNamespaceAndPath(ModInfo.ID, "textures/gui/changelog.png"),
|
||||
|
||||
+18
-12
@@ -1,19 +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 IServerKeyedClientLevel overrideWrapper = null;
|
||||
private boolean useOverrideWrapper = false;
|
||||
|
||||
|
||||
//=============//
|
||||
@@ -29,20 +31,24 @@ public class KeyedClientLevelManager implements IKeyedClientLevelManager
|
||||
//======================//
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IServerKeyedClientLevel getServerKeyedLevel() { return this.serverKeyedLevel; }
|
||||
public void setServerKeyedLevel(IServerKeyedClientLevel clientLevel) { this.overrideWrapper = clientLevel; }
|
||||
@Override
|
||||
public IServerKeyedClientLevel getOverrideWrapper() { return this.overrideWrapper; }
|
||||
|
||||
@Override
|
||||
public IServerKeyedClientLevel setServerKeyedLevel(IClientLevelWrapper clientLevel, String levelKey)
|
||||
public IServerKeyedClientLevel getServerKeyedLevel(ILevelWrapper level, String serverLevelKey)
|
||||
{
|
||||
IServerKeyedClientLevel keyedLevel = new ServerKeyedClientLevel((ClientLevel) clientLevel.getWrappedMcObject(), levelKey);
|
||||
this.serverKeyedLevel = keyedLevel;
|
||||
return keyedLevel;
|
||||
Objects.requireNonNull(level);
|
||||
Objects.requireNonNull(serverLevelKey);
|
||||
return new ServerKeyedClientLevel((ClientLevel) level.getWrappedMcObject(), serverLevelKey);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clearKeyedLevel() { this.serverKeyedLevel = null; }
|
||||
public void setUseOverrideWrapper(boolean useOverrideWrapper) { this.useOverrideWrapper = useOverrideWrapper; }
|
||||
@Override
|
||||
public boolean hasLevelSet() { return this.serverKeyedLevel != null; }
|
||||
public boolean getUseOverrideWrapper() { return this.useOverrideWrapper; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
-3
@@ -18,7 +18,4 @@ public class ServerKeyedClientLevel extends ClientLevelWrapper implements IServe
|
||||
@Override
|
||||
public String getServerLevelKey() { return this.serverLevelKey; }
|
||||
|
||||
@Override
|
||||
public String getDimensionName() { return this.getServerLevelKey(); }
|
||||
|
||||
}
|
||||
|
||||
+6
-17
@@ -39,14 +39,14 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftCli
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IProfilerWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
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.client.resources.model.ModelManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
#if MC_VER < MC_1_19_2
|
||||
@@ -221,19 +221,14 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IClientLevelWrapper getWrappedClientLevel() { return this.getWrappedClientLevel(false); }
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IClientLevelWrapper getWrappedClientLevel(boolean bypassLevelKeyManager)
|
||||
public IClientLevelWrapper getWrappedClientLevel()
|
||||
{
|
||||
ClientLevel level = MINECRAFT.level;
|
||||
if (level == null)
|
||||
if (MINECRAFT.level == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return ClientLevelWrapper.getWrapper(level, bypassLevelKeyManager);
|
||||
return ClientLevelWrapper.getWrapperIgnoringOverride(MINECRAFT.level);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -272,10 +267,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
|
||||
@@ -315,7 +307,4 @@ public class MinecraftClientWrapper implements IMinecraftClientWrapper, IMinecra
|
||||
@Override
|
||||
public void executeOnRenderThread(Runnable runnable) { MINECRAFT.execute(runnable); }
|
||||
|
||||
@Override
|
||||
public boolean isWorldNew() { throw new UnsupportedOperationException("Not Implemented"); }
|
||||
|
||||
}
|
||||
|
||||
+5
-24
@@ -6,45 +6,26 @@ import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import java.io.File;
|
||||
|
||||
//@Environment(EnvType.SERVER)
|
||||
public class MinecraftServerWrapper implements IMinecraftSharedWrapper
|
||||
public class MinecraftDedicatedServerWrapper implements IMinecraftSharedWrapper
|
||||
{
|
||||
public static final MinecraftServerWrapper INSTANCE = new MinecraftServerWrapper();
|
||||
|
||||
public static final MinecraftDedicatedServerWrapper INSTANCE = new MinecraftDedicatedServerWrapper();
|
||||
private MinecraftDedicatedServerWrapper() { }
|
||||
public DedicatedServer dedicatedServer = null;
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
private MinecraftServerWrapper() { }
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// methods //
|
||||
//=========//
|
||||
|
||||
@Override
|
||||
public boolean isDedicatedServer() { return true; }
|
||||
|
||||
@Override
|
||||
public File getInstallationDirectory()
|
||||
{
|
||||
if (this.dedicatedServer == null)
|
||||
{
|
||||
throw new IllegalStateException("Trying to get Installation Direction before Dedicated server completed initialization!");
|
||||
throw new IllegalStateException("Trying to get Installation Direction before Dedicated server complete initialization!");
|
||||
}
|
||||
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
return this.dedicatedServer.getServerDirectory();
|
||||
#else
|
||||
return this.dedicatedServer.getServerDirectory().toFile();
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorldNew()
|
||||
{ return this.dedicatedServer.getWorldData().overworldData().isInitialized(); }
|
||||
|
||||
}
|
||||
+16
-6
@@ -21,26 +21,29 @@ package com.seibel.distanthorizons.common.wrappers.minecraft;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.mojang.blaze3d.pipeline.RenderTarget;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.seibel.distanthorizons.common.wrappers.McObjectConverter;
|
||||
import com.seibel.distanthorizons.common.wrappers.WrapperFactory;
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.LightMapWrapper;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
|
||||
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.ILightMapWrapper;
|
||||
|
||||
#if MC_VER >= MC_1_17_1
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
#endif
|
||||
|
||||
#if MC_VER < MC_1_19_4
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
#else
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
#endif
|
||||
#if MC_VER >= MC_1_20_2
|
||||
import net.minecraft.client.renderer.chunk.SectionRenderDispatcher;
|
||||
@@ -50,14 +53,20 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.AbstractOpt
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IDimensionTypeWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import com.seibel.distanthorizons.core.util.math.Mat4f;
|
||||
import com.seibel.distanthorizons.core.util.math.Vec3d;
|
||||
import com.seibel.distanthorizons.core.util.math.Vec3f;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ISodiumAccessor;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
#if MC_VER < MC_1_17_1
|
||||
import net.minecraft.tags.FluidTags;
|
||||
@@ -67,6 +76,7 @@ import org.lwjgl.opengl.GL15;
|
||||
#else
|
||||
import net.minecraft.world.level.material.FogType;
|
||||
#endif
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -155,7 +165,7 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
|
||||
if (MC.level.dimensionType().hasSkyLight())
|
||||
{
|
||||
float frameTime;
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
frameTime = MC.getFrameTime();
|
||||
#else
|
||||
frameTime = MC.getTimer().getRealtimeDeltaTicks();
|
||||
|
||||
-15
@@ -1,15 +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();
|
||||
|
||||
#if MC_VER == MC_1_16_5
|
||||
void distantHorizons$setDimensionChangeDestination(ServerLevel dimensionChangeDestination);
|
||||
#endif
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.seibel.distanthorizons.common.wrappers.misc;
|
||||
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IMutableBlockPosWrapper;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
public class MutableBlockPosWrapper implements IMutableBlockPosWrapper
|
||||
{
|
||||
public final BlockPos.MutableBlockPos pos;
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
public MutableBlockPosWrapper()
|
||||
{
|
||||
this.pos = new BlockPos.MutableBlockPos();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===========//
|
||||
// overrides //
|
||||
//===========//
|
||||
|
||||
@Override
|
||||
public Object getWrappedMcObject() { return this.pos; }
|
||||
|
||||
}
|
||||
+26
-87
@@ -1,115 +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 the 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 final ServerPlayer serverPlayer;
|
||||
|
||||
public static ServerPlayerWrapper getWrapper(ServerPlayer serverPlayer)
|
||||
{
|
||||
return serverPlayerWrapperMap.computeIfAbsent(serverPlayer, ServerPlayerWrapper::new);
|
||||
}
|
||||
|
||||
private ServerPlayerWrapper(ServerPlayer serverPlayer)
|
||||
{
|
||||
this.serverPlayer = serverPlayer;
|
||||
}
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
public UUID getUUID()
|
||||
{
|
||||
return serverPlayer.getUUID();
|
||||
}
|
||||
|
||||
public static ServerPlayerWrapper getWrapper(ServerPlayer serverPlayer)
|
||||
{ return serverPlayerWrapperMap.computeIfAbsent(serverPlayer.connection, ignored -> new ServerPlayerWrapper(serverPlayer.connection)); }
|
||||
|
||||
private ServerPlayerWrapper(ServerGamePacketListenerImpl connection) { this.connection = connection; }
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// getters //
|
||||
//=========//
|
||||
|
||||
private ServerPlayer getServerPlayer() { return this.connection.player; }
|
||||
|
||||
@Override
|
||||
public String getName() { return this.getServerPlayer().getName().getString(); }
|
||||
|
||||
@Override
|
||||
public IServerLevelWrapper getLevel()
|
||||
{
|
||||
ServerLevel level = ((IMixinServerPlayer) this.getServerPlayer()).distantHorizons$getDimensionChangeDestination();
|
||||
if (level == null)
|
||||
{
|
||||
#if MC_VER < MC_1_20_1
|
||||
level = this.getServerPlayer().getLevel();
|
||||
#else
|
||||
level = this.getServerPlayer().serverLevel();
|
||||
#endif
|
||||
}
|
||||
|
||||
return ServerLevelWrapper.getWrapper(level);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3d getPosition()
|
||||
{
|
||||
Vec3 position = this.getServerPlayer().position();
|
||||
return new Vec3d(position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewDistance() { return this.getServerPlayer().server.getPlayerList().getViewDistance(); }
|
||||
|
||||
@Override
|
||||
public SocketAddress getRemoteAddress()
|
||||
{
|
||||
#if MC_VER >= MC_1_19_4
|
||||
return this.getServerPlayer().connection.getRemoteAddress();
|
||||
#else // < 1.19.4
|
||||
return this.getServerPlayer().connection.connection.getRemoteAddress();
|
||||
#if MC_VER < MC_1_20_1
|
||||
return ServerLevelWrapper.getWrapper(this.serverPlayer.getLevel());
|
||||
#else
|
||||
return ServerLevelWrapper.getWrapper(this.serverPlayer.serverLevel());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
// base overrides //
|
||||
//================//
|
||||
|
||||
@Override
|
||||
public Object getWrappedMcObject() { return this.getServerPlayer(); }
|
||||
|
||||
@Override
|
||||
public String toString() { return "Wrapped{" + this.getServerPlayer() + "}"; }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
public Object getWrappedMcObject()
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof ServerPlayerWrapper))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ServerPlayerWrapper that = (ServerPlayerWrapper) obj;
|
||||
return Objects.equal(this.connection, that.connection);
|
||||
return serverPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() { return Objects.hashCode(this.connection); }
|
||||
public String toString()
|
||||
{
|
||||
return "Wrapped{" + serverPlayer.toString() + "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+19
-34
@@ -7,12 +7,13 @@ import com.seibel.distanthorizons.common.wrappers.block.BiomeWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.block.BlockStateWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.block.ClientBlockStateColorCache;
|
||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
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.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.util.ColorUtil;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
@@ -25,12 +26,10 @@ import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.chunk.ChunkSource;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -70,28 +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
|
||||
@@ -124,6 +118,8 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//====================//
|
||||
// base level methods //
|
||||
//====================//
|
||||
@@ -183,10 +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; }
|
||||
@@ -215,12 +207,12 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
@Override
|
||||
public IChunkWrapper tryGetChunk(DhChunkPos pos)
|
||||
{
|
||||
if (!this.level.hasChunk(pos.getX(), pos.getZ()))
|
||||
if (!this.level.hasChunk(pos.x, pos.z))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
ChunkAccess chunk = this.level.getChunk(pos.getX(), pos.getZ(), ChunkStatus.EMPTY, false);
|
||||
ChunkAccess chunk = this.level.getChunk(pos.x, pos.z, ChunkStatus.EMPTY, false);
|
||||
if (chunk == null)
|
||||
{
|
||||
return null;
|
||||
@@ -275,13 +267,6 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
return this.parentDhLevel.getGenericRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getCloudColor(float tickDelta)
|
||||
{
|
||||
Vec3 colorVec3 = this.level.getCloudColor(tickDelta);
|
||||
return new Color((float)colorVec3.x, (float)colorVec3.y, (float)colorVec3.z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//================//
|
||||
@@ -296,7 +281,7 @@ public class ClientLevelWrapper implements IClientLevelWrapper
|
||||
return "Wrapped{null}";
|
||||
}
|
||||
|
||||
return "Wrapped{" + this.level.toString() + "@" + this.getDimensionName() + "}";
|
||||
return "Wrapped{" + this.level.toString() + "@" + this.getDimensionType().getDimensionName() + "}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-14
@@ -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_16_5
|
||||
// effectsLocation() is marked as client only, so using the backing field directly
|
||||
return dimensionType.effectsLocation.getPath();
|
||||
#else
|
||||
return this.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,9 +85,7 @@ public class DimensionTypeWrapper implements IDimensionTypeWrapper
|
||||
return this.dimensionType;
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
+35
-27
@@ -30,7 +30,7 @@ import com.seibel.distanthorizons.common.wrappers.block.BlockStateWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper;
|
||||
@@ -48,6 +48,7 @@ import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
#endif
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @version 2022-9-16
|
||||
@@ -81,27 +82,42 @@ public class ServerLevelWrapper implements IServerLevelWrapper
|
||||
//=========//
|
||||
|
||||
@Override
|
||||
public File getSaveFolder() { return this.level.getChunkSource().getDataStorage().dataFolder; }
|
||||
public File getSaveFolder()
|
||||
{
|
||||
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(); }
|
||||
public DimensionTypeWrapper getDimensionType()
|
||||
{
|
||||
return DimensionTypeWrapper.getDimensionTypeWrapper(level.dimensionType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EDhApiLevelType getLevelType() { return EDhApiLevelType.SERVER_LEVEL; }
|
||||
|
||||
public ServerLevel getLevel() { return this.level; }
|
||||
public ServerLevel getLevel()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCeiling() { return this.level.dimensionType().hasCeiling(); }
|
||||
public boolean hasCeiling()
|
||||
{
|
||||
return level.dimensionType().hasCeiling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSkyLight() { return this.level.dimensionType().hasSkyLight(); }
|
||||
public boolean hasSkyLight()
|
||||
{
|
||||
return level.dimensionType().hasSkyLight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHeight() { return this.level.getHeight(); }
|
||||
public int getMaxHeight()
|
||||
{
|
||||
return level.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinHeight()
|
||||
@@ -109,45 +125,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.x, pos.z)) return null;
|
||||
ChunkAccess chunk = level.getChunk(pos.x, pos.z, 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
|
||||
@@ -178,6 +186,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() + "}"; }
|
||||
|
||||
}
|
||||
|
||||
+25
-26
@@ -134,7 +134,7 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
{
|
||||
for (int i = 0; i < 11; i++)
|
||||
{
|
||||
this.times.add(new Rolling(SIZE));
|
||||
times.add(new Rolling(SIZE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,25 +144,19 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
{
|
||||
String name = e.name;
|
||||
int index = Arrays.asList(TIME_NAMES).indexOf(name);
|
||||
if (index == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
this.times.get(index).add(e.timeNs);
|
||||
if (index == -1) continue;
|
||||
times.get(index).add(e.timeNs);
|
||||
}
|
||||
this.times.get(0).add(event.getTotalTimeNs());
|
||||
times.get(0).add(event.getTotalTimeNs());
|
||||
}
|
||||
|
||||
@Override public String toString()
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < this.times.size(); i++)
|
||||
for (int i = 0; i < times.size(); i++)
|
||||
{
|
||||
if (this.times.get(i).getAverage() == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
sb.append(TIME_NAMES[i]).append(": ").append(this.times.get(i).getAverage()).append("\n");
|
||||
if (times.get(i).getAverage() == 0) continue;
|
||||
sb.append(TIME_NAMES[i]).append(": ").append(times.get(i).getAverage()).append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -192,13 +186,13 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
|
||||
public RegionFileStorageExternalCache getOrCreateRegionFileCache(RegionFileStorage storage)
|
||||
{
|
||||
RegionFileStorageExternalCache cache = this.regionFileStorageCacheRef.get();
|
||||
RegionFileStorageExternalCache cache = regionFileStorageCacheRef.get();
|
||||
if (cache == null)
|
||||
{
|
||||
cache = new RegionFileStorageExternalCache(storage);
|
||||
if (!this.regionFileStorageCacheRef.compareAndSet(null, cache))
|
||||
if (!regionFileStorageCacheRef.compareAndSet(null, cache))
|
||||
{
|
||||
cache = this.regionFileStorageCacheRef.get();
|
||||
cache = regionFileStorageCacheRef.get();
|
||||
}
|
||||
}
|
||||
return cache;
|
||||
@@ -310,17 +304,17 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
|
||||
public <T> T joinSync(CompletableFuture<T> future)
|
||||
{
|
||||
if (!this.unsafeThreadingRecorded && !future.isDone())
|
||||
if (!unsafeThreadingRecorded && !future.isDone())
|
||||
{
|
||||
EVENT_LOGGER.error("Unsafe MultiThreading in Chunk Generator: ", new RuntimeException("Concurrent future"));
|
||||
EVENT_LOGGER.error("To increase stability, it is recommended to set world generation threads count to 1.");
|
||||
this.unsafeThreadingRecorded = true;
|
||||
unsafeThreadingRecorded = true;
|
||||
}
|
||||
|
||||
return future.join();
|
||||
}
|
||||
|
||||
@Override public void updateAllFutures()
|
||||
public void updateAllFutures()
|
||||
{
|
||||
if (this.unknownExceptionCount > 0)
|
||||
{
|
||||
@@ -404,8 +398,8 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
int borderSize = MAX_WORLD_GEN_CHUNK_BORDER_NEEDED;
|
||||
// genEvent.size - 1 converts the even width size to an odd number for MC compatability
|
||||
int refSize = (genEvent.size - 1) + (borderSize * 2);
|
||||
int refPosX = genEvent.minPos.getX() - borderSize;
|
||||
int refPosZ = genEvent.minPos.getZ() - borderSize;
|
||||
int refPosX = genEvent.minPos.x - borderSize;
|
||||
int refPosZ = genEvent.minPos.z - borderSize;
|
||||
|
||||
LightGetterAdaptor lightGetterAdaptor = new LightGetterAdaptor(this.params.level);
|
||||
DummyLightEngine dummyLightEngine = new DummyLightEngine(lightGetterAdaptor);
|
||||
@@ -494,8 +488,8 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
{
|
||||
chunkWrapper.setBlockLightStorage(chunkBlockLightingByDhPos.get(chunkWrapper.getChunkPos()));
|
||||
chunkWrapper.setSkyLightStorage(chunkSkyLightingByDhPos.get(chunkWrapper.getChunkPos()));
|
||||
chunkWrapper.setIsDhBlockLightCorrect(true);
|
||||
chunkWrapper.setIsDhSkyLightCorrect(true);
|
||||
chunkWrapper.setUseDhLighting(true);
|
||||
chunkWrapper.setIsDhLightCorrect(true);
|
||||
}
|
||||
|
||||
chunkWrappersByDhPos.put(chunkPos, chunkWrapper);
|
||||
@@ -537,6 +531,11 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!wrappedChunk.isLightCorrect())
|
||||
{
|
||||
throw new RuntimeException("The generated chunk somehow has isLightCorrect() returning false");
|
||||
}
|
||||
|
||||
boolean isFull = ChunkWrapper.getStatus(target) == ChunkStatus.FULL || target instanceof LevelChunk;
|
||||
#if MC_VER >= MC_1_18_2
|
||||
boolean isPartial = target.isOldNoiseGeneration();
|
||||
@@ -824,9 +823,9 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv
|
||||
Heightmap.primeHeightmaps(((ChunkWrapper)centerChunk).getChunk(), ChunkStatus.FEATURES.heightmapsAfter());
|
||||
|
||||
// pre-generated chunks should have lighting but new ones won't
|
||||
if (!centerChunk.isDhBlockLightingCorrect())
|
||||
if (!centerChunk.isLightCorrect())
|
||||
{
|
||||
DhLightingEngine.INSTANCE.bakeChunkBlockLighting(centerChunk, iChunkWrapperList, maxSkyLight);
|
||||
DhLightingEngine.INSTANCE.lightChunk(centerChunk, iChunkWrapperList, maxSkyLight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -85,7 +85,7 @@ import net.minecraft.world.level.material.Fluids;
|
||||
#if MC_VER == MC_1_20_6
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.status.ChunkType;
|
||||
#elif MC_VER >= MC_1_21_1
|
||||
#elif MC_VER == MC_1_21
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.status.ChunkType;
|
||||
#endif
|
||||
@@ -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))
|
||||
@@ -325,7 +325,7 @@ public class ChunkLoader
|
||||
}
|
||||
private static
|
||||
#if MC_VER < MC_1_20_6 ChunkStatus.ChunkType
|
||||
#elif MC_VER < MC_1_21_1 ChunkType
|
||||
#elif MC_VER < MC_1_21 ChunkType
|
||||
#else ChunkType #endif
|
||||
readChunkType(CompoundTag tagLevel)
|
||||
{
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.seibel.distanthorizons.common.wrappers.worldGeneration.mimicObject;
|
||||
|
||||
#if MC_VER >= MC_1_21_1
|
||||
#if MC_VER >= MC_1_21
|
||||
|
||||
import net.minecraft.server.level.GenerationChunkHolder;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
|
||||
+3
-18
@@ -20,6 +20,7 @@
|
||||
package com.seibel.distanthorizons.common.wrappers.worldGeneration.mimicObject;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
@@ -62,7 +63,7 @@ import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.status.*;
|
||||
#endif
|
||||
|
||||
#if MC_VER >= MC_1_21_1
|
||||
#if MC_VER == MC_1_21
|
||||
import net.minecraft.util.StaticCache2D;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.server.level.GenerationChunkHolder;
|
||||
@@ -126,7 +127,7 @@ public class DhLitWorldGenRegion extends WorldGenRegion
|
||||
{
|
||||
#if MC_VER == MC_1_16_5
|
||||
super(serverLevel, chunkList);
|
||||
#elif MC_VER < MC_1_21_1
|
||||
#elif MC_VER < MC_1_21
|
||||
super(serverLevel, chunkList, chunkStatus, writeRadius);
|
||||
#else
|
||||
super(serverLevel,
|
||||
@@ -234,22 +235,6 @@ public class DhLitWorldGenRegion extends WorldGenRegion
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* This needs to be manually overridden to make sure Lithium 0.11.2 and lower
|
||||
* don't try to get null chunks. <br><br>
|
||||
*
|
||||
* Problematic Lithium code was removed in 0.13.0 (MC 1.21.1) and higher: <br>
|
||||
* https://github.com/CaffeineMC/lithium-fabric/commit/b7cfd53a1ed0197e1d13dea2799b898eb52ecab3
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public BlockState getBlockState(BlockPos blockPos)
|
||||
{
|
||||
int chunkX = SectionPos.blockToSectionCoord(blockPos.getX());
|
||||
int chunkZ = SectionPos.blockToSectionCoord(blockPos.getZ());
|
||||
return this.getChunk(chunkX, chunkZ).getBlockState(blockPos);
|
||||
}
|
||||
|
||||
/** Skip BlockEntity stuff. They aren't needed for our use case. */
|
||||
@Override
|
||||
public boolean addFreshEntity(@NotNull Entity entity) { return true; }
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ public final class StepBiomes
|
||||
}
|
||||
else if (chunk instanceof ProtoChunk)
|
||||
{
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
((ProtoChunk) chunk).setStatus(STATUS);
|
||||
#else
|
||||
((ProtoChunk) chunk).setPersistedStatus(STATUS);
|
||||
@@ -89,7 +89,7 @@ public final class StepBiomes
|
||||
#elif MC_VER < MC_1_19_4
|
||||
chunk = this.environment.joinSync(this.environment.params.generator.createBiomes(this.environment.params.biomes, Runnable::run, this.environment.params.randomState, Blender.of(worldGenRegion),
|
||||
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
|
||||
#elif MC_VER < MC_1_21_1
|
||||
#elif MC_VER < MC_1_21
|
||||
chunk = this.environment.joinSync(this.environment.params.generator.createBiomes(Runnable::run, this.environment.params.randomState, Blender.of(worldGenRegion),
|
||||
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
|
||||
#else
|
||||
|
||||
+2
-2
@@ -66,7 +66,7 @@ public final class StepFeatures
|
||||
}
|
||||
else if (chunk instanceof ProtoChunk)
|
||||
{
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
((ProtoChunk) chunk).setStatus(STATUS);
|
||||
#else
|
||||
((ProtoChunk) chunk).setPersistedStatus(STATUS);
|
||||
@@ -80,7 +80,7 @@ public final class StepFeatures
|
||||
worldGenRegion.setOverrideCenter(chunk.getPos());
|
||||
environment.params.generator.applyBiomeDecoration(worldGenRegion, tParams.structFeat);
|
||||
#else
|
||||
if (worldGenRegion.hasChunk(chunkWrapper.getChunkPos().getX(), chunkWrapper.getChunkPos().getZ()))
|
||||
if (worldGenRegion.hasChunk(chunkWrapper.getChunkPos().x, chunkWrapper.getChunkPos().z))
|
||||
{
|
||||
this.environment.params.generator.applyBiomeDecoration(worldGenRegion, chunk, tParams.structFeat.forWorldGenRegion(worldGenRegion));
|
||||
}
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ public final class StepNoise
|
||||
continue;
|
||||
}
|
||||
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
((ProtoChunk) chunk).setStatus(STATUS);
|
||||
#else
|
||||
((ProtoChunk) chunk).setPersistedStatus(STATUS);
|
||||
@@ -87,7 +87,7 @@ public final class StepNoise
|
||||
#elif MC_VER < MC_1_19_2
|
||||
chunk = this.environment.joinSync(this.environment.params.generator.fillFromNoise(Runnable::run, Blender.of(worldGenRegion),
|
||||
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
|
||||
#elif MC_VER < MC_1_21_1
|
||||
#elif MC_VER < MC_1_21
|
||||
chunk = this.environment.joinSync(this.environment.params.generator.fillFromNoise(Runnable::run, Blender.of(worldGenRegion), this.environment.params.randomState,
|
||||
tParams.structFeat.forWorldGenRegion(worldGenRegion), chunk));
|
||||
#else
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public final class StepStructureReference
|
||||
}
|
||||
else if (chunk instanceof ProtoChunk)
|
||||
{
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
((ProtoChunk) chunk).setStatus(STATUS);
|
||||
#else
|
||||
((ProtoChunk) chunk).setPersistedStatus(STATUS);
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public final class StepStructureStart
|
||||
}
|
||||
else if (chunk instanceof ProtoChunk)
|
||||
{
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
((ProtoChunk) chunk).setStatus(STATUS);
|
||||
#else
|
||||
((ProtoChunk) chunk).setPersistedStatus(STATUS);
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public final class StepSurface
|
||||
}
|
||||
else if (chunk instanceof ProtoChunk)
|
||||
{
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
((ProtoChunk) chunk).setStatus(STATUS);
|
||||
#else
|
||||
((ProtoChunk) chunk).setPersistedStatus(STATUS);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.seibel.distanthorizons.common.mixins",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"client.MixinDebugScreenOverlay",
|
||||
"client.MixinFogRenderer",
|
||||
"client.MixinGameRenderer",
|
||||
"client.MixinLightTexture"
|
||||
],
|
||||
"server": []
|
||||
}
|
||||
+1
-1
Submodule coreSubProjects updated: 5b746a9534...377d0fbe12
+3
-11
@@ -10,17 +10,14 @@ loom {
|
||||
client {
|
||||
client()
|
||||
setConfigName("Fabric Client")
|
||||
ideConfigGenerated(true) // When true a run configuration file will be generated for IDE's. By default only set to true for the root project.
|
||||
runDir("../run/client")
|
||||
vmArgs("-Dio.netty.leakDetection.level=advanced") // https://netty.io/wiki/reference-counted-objects.html#leak-detection-levels
|
||||
programArgs("--username", "Dev")
|
||||
ideConfigGenerated(true)
|
||||
runDir("../run")
|
||||
}
|
||||
server {
|
||||
server()
|
||||
setConfigName("Fabric Server")
|
||||
ideConfigGenerated(true)
|
||||
runDir("../run/server")
|
||||
vmArgs("-Dio.netty.leakDetection.level=advanced")
|
||||
runDir("../run")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,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))
|
||||
|
||||
@@ -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.AbstractNetworkMessage;
|
||||
#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");
|
||||
@@ -123,11 +117,8 @@ public class FabricClientProxy implements AbstractModInitializer.IEventProxy
|
||||
// ClientChunkLoadEvent
|
||||
ClientChunkEvents.CHUNK_LOAD.register((level, chunk) ->
|
||||
{
|
||||
if (MC.clientConnectedToDedicatedServer())
|
||||
{
|
||||
IClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper(level);
|
||||
SharedApi.INSTANCE.chunkLoadEvent(new ChunkWrapper(chunk, level, wrappedLevel), wrappedLevel);
|
||||
}
|
||||
IClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper(level);
|
||||
SharedApi.INSTANCE.chunkLoadEvent(new ChunkWrapper(chunk, level, wrappedLevel), wrappedLevel);
|
||||
});
|
||||
|
||||
// (kinda) block break event
|
||||
@@ -209,6 +200,14 @@ public class FabricClientProxy implements AbstractModInitializer.IEventProxy
|
||||
});
|
||||
|
||||
|
||||
// Client Chunk Save
|
||||
ClientChunkEvents.CHUNK_UNLOAD.register((level, chunk) ->
|
||||
{
|
||||
IClientLevelWrapper wrappedLevel = ClientLevelWrapper.getWrapper(level);
|
||||
SharedApi.INSTANCE.chunkUnloadEvent(new ChunkWrapper(chunk, level, wrappedLevel), wrappedLevel);
|
||||
});
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// render event //
|
||||
@@ -228,14 +227,14 @@ public class FabricClientProxy implements AbstractModInitializer.IEventProxy
|
||||
this.clientApi.renderLods(ClientLevelWrapper.getWrapper(renderContext.world()),
|
||||
modelViewMatrix,
|
||||
projectionMatrix,
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
renderContext.tickDelta()
|
||||
#else
|
||||
renderContext.tickCounter().getGameTimeDeltaTicks()
|
||||
#endif
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
// Debug keyboard event
|
||||
// FIXME: Use better hooks so it doesn't trigger key press events in text boxes
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client ->
|
||||
@@ -252,29 +251,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();
|
||||
AbstractNetworkMessage 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 +290,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,15 +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()); }
|
||||
@@ -143,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.AbstractNetworkMessage;
|
||||
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 sendToServer(AbstractNetworkMessage 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 sendToClient(ServerPlayer serverPlayer, AbstractNetworkMessage 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.AbstractNetworkMessage;
|
||||
import com.seibel.distanthorizons.common.AbstractPluginPacketSender;
|
||||
#endif
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -50,26 +40,21 @@ public class FabricServerProxy implements AbstractModInitializer.IEventProxy
|
||||
private static final ServerApi SERVER_API = ServerApi.INSTANCE;
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
|
||||
private final boolean isDedicatedServer;
|
||||
private final boolean isDedicated;
|
||||
public static Supplier<Boolean> isGenerationThreadChecker = null;
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
public FabricServerProxy(boolean isDedicatedServer)
|
||||
public FabricServerProxy(boolean isDedicated)
|
||||
{
|
||||
this.isDedicatedServer = isDedicatedServer;
|
||||
this.isDedicated = isDedicated;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO rename
|
||||
private boolean isValidTime()
|
||||
{
|
||||
if (this.isDedicatedServer)
|
||||
if (isDedicated)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -83,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");
|
||||
@@ -106,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.isDedicatedServer);
|
||||
ServerApi.INSTANCE.serverLoadEvent(isDedicated);
|
||||
}
|
||||
});
|
||||
// ServerWorldUnloadEvent
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register((server) ->
|
||||
{
|
||||
if (this.isValidTime())
|
||||
if (isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverUnloadEvent();
|
||||
}
|
||||
@@ -123,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),
|
||||
@@ -152,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, originLevel, destinationLevel) ->
|
||||
{
|
||||
if (this.isValidTime())
|
||||
{
|
||||
ServerApi.INSTANCE.serverPlayerLevelChangeEvent(
|
||||
this.getServerPlayerWrapper(player),
|
||||
this.getServerLevelWrapper(originLevel),
|
||||
this.getServerLevelWrapper(destinationLevel)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.isDedicatedServer)
|
||||
{
|
||||
#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();
|
||||
AbstractNetworkMessage message = AbstractPluginPacketSender.decodeMessage(buffer);
|
||||
if (message != null)
|
||||
{
|
||||
ServerApi.INSTANCE.pluginMessageReceived(ServerPlayerWrapper.getWrapper(serverPlayer), message);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+28
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.seibel.distanthorizons.fabric.mixins.client;
|
||||
|
||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||
import net.minecraft.client.gui.components.DebugScreenOverlay;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(DebugScreenOverlay.class)
|
||||
public class MixinDebugScreenOverlay
|
||||
{
|
||||
|
||||
@Inject(method = "getSystemInformation", at = @At("RETURN"))
|
||||
private void addCustomF3(CallbackInfoReturnable<List<String>> cir)
|
||||
{
|
||||
List<String> messages = cir.getReturnValue();
|
||||
F3Screen.addStringToDisplay(messages);
|
||||
}
|
||||
|
||||
}
|
||||
+19
-1
@@ -116,7 +116,7 @@ public class MixinLevelRenderer
|
||||
ClientApi.INSTANCE.renderDeferredLods(ClientLevelWrapper.getWrapper(this.level),
|
||||
mcModelViewMatrix,
|
||||
mcProjectionMatrix,
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
Minecraft.getInstance().getFrameTime()
|
||||
#else
|
||||
Minecraft.getInstance().getTimer().getRealtimeDeltaTicks()
|
||||
@@ -131,4 +131,22 @@ public class MixinLevelRenderer
|
||||
}
|
||||
}
|
||||
|
||||
#if MC_VER < MC_1_19_4
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runUpdates(IZZ)I"), method = "renderLevel")
|
||||
public void callAfterRunUpdates(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci)
|
||||
#elif MC_VER < MC_1_20_1
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runUpdates(IZZ)I"), method = "renderLevel")
|
||||
public void callAfterRunUpdates(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci)
|
||||
#elif MC_VER < MC_1_20_6
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I"), method = "renderLevel")
|
||||
private void callAfterRunUpdates(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci)
|
||||
#else
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I"), method = "renderLevel")
|
||||
private void callAfterRunUpdates(CallbackInfo ci)
|
||||
#endif
|
||||
{
|
||||
ChunkWrapper.syncedUpdateClientLightStatus();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+1
-27
@@ -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,22 +113,6 @@ 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(); }
|
||||
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
#endif
|
||||
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
import net.minecraft.client.gui.screens.OptionsScreen;
|
||||
#else
|
||||
import net.minecraft.client.gui.screens.options.OptionsScreen;
|
||||
@@ -64,7 +64,7 @@ public class MixinOptionsScreen extends Screen
|
||||
/** Texture used for the config opening button */
|
||||
@Unique
|
||||
private static final ResourceLocation ICON_TEXTURE =
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
new ResourceLocation(ModInfo.ID, "textures/gui/button.png");
|
||||
#else
|
||||
ResourceLocation.fromNamespaceAndPath(ModInfo.ID, "textures/gui/button.png");
|
||||
|
||||
+60
-2
@@ -1,6 +1,8 @@
|
||||
package com.seibel.distanthorizons.fabric.mixins.server;
|
||||
|
||||
import com.seibel.distanthorizons.common.commonMixins.MixinChunkMapCommon;
|
||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.api.internal.ServerApi;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
@@ -30,6 +32,62 @@ public class MixinChunkMap
|
||||
// don't need the chunk(s) before MC has finished saving them
|
||||
@Inject(method = "save", at = @At(value = "RETURN", target = CHUNK_SERIALIZER_WRITE))
|
||||
private void onChunkSave(ChunkAccess chunk, CallbackInfoReturnable<Boolean> ci)
|
||||
{ MixinChunkMapCommon.onChunkSave(this.level, chunk, ci); }
|
||||
{
|
||||
// true means a chunk was saved to disk
|
||||
if (ci.getReturnValue())
|
||||
{
|
||||
// TODO is this validation necessary since we are checking above if
|
||||
// the callback return value should state if the chunk was actually saved or not?
|
||||
// Do we trust it to always be correct?
|
||||
|
||||
//=====================================//
|
||||
// corrupt/incomplete chunk validation //
|
||||
//=====================================//
|
||||
|
||||
// MC has a tendency to try saving incomplete or corrupted chunks (which show up as empty or black chunks)
|
||||
// this logic should prevent that from happening
|
||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
||||
if (chunk.isUnsaved() || chunk.getUpgradeData() != null || !chunk.isLightCorrect())
|
||||
{
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (chunk.isUnsaved() || chunk.isUpgrading() || !chunk.isLightCorrect())
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//==================//
|
||||
// biome validation //
|
||||
//==================//
|
||||
|
||||
// some chunks may be missing their biomes, which cause issues when attempting to save them
|
||||
#if MC_VER == MC_1_16_5 || MC_VER == MC_1_17_1
|
||||
if (chunk.getBiomes() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#else
|
||||
try
|
||||
{
|
||||
// this will throw an exception if the biomes aren't set up
|
||||
chunk.getNoiseBiome(0,0,0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
ServerApi.INSTANCE.serverChunkSaveEvent(
|
||||
new ChunkWrapper(chunk, this.level, ServerLevelWrapper.getWrapper(this.level)),
|
||||
ServerLevelWrapper.getWrapper(this.level)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#if MC_VER == MC_1_16_5
|
||||
package com.seibel.distanthorizons.fabric.mixins.server;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.IMixinServerPlayer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public class MixinEntity
|
||||
{
|
||||
@Inject(at = @At("TAIL"), method = "setLevel")
|
||||
public void setLevel(Level level, CallbackInfo ci)
|
||||
{
|
||||
if (this instanceof IMixinServerPlayer)
|
||||
{
|
||||
((IMixinServerPlayer) this).distantHorizons$setDimensionChangeDestination((ServerLevel) level);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
package com.seibel.distanthorizons.fabric.mixins.server;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public class MixinEntity
|
||||
{
|
||||
}
|
||||
#endif
|
||||
-76
@@ -1,76 +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; }
|
||||
|
||||
#if MC_VER == MC_1_16_5
|
||||
@Override
|
||||
public void distantHorizons$setDimensionChangeDestination(ServerLevel dimensionChangeDestination)
|
||||
{ this.dimensionChangeDestination = dimensionChangeDestination; }
|
||||
#endif
|
||||
|
||||
@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)
|
||||
{ this.dimensionChangeDestination = null; }
|
||||
#elif MC_VER >= MC_1_17_1
|
||||
@Inject(at = @At("RETURN"), method = "setLevel")
|
||||
public void setLevel(ServerLevel level, CallbackInfo ci)
|
||||
{ this.dimensionChangeDestination = null; }
|
||||
#endif
|
||||
|
||||
}
|
||||
+3
-3
@@ -1,16 +1,16 @@
|
||||
package com.seibel.distanthorizons.fabric.testing;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import com.seibel.distanthorizons.api.DhApi;
|
||||
import com.seibel.distanthorizons.api.interfaces.override.worldGenerator.IDhApiWorldGenerator;
|
||||
import com.seibel.distanthorizons.api.methods.events.abstractEvents.DhApiLevelLoadEvent;
|
||||
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiEventParam;
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.fabric.FabricServerProxy;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class TestWorldGenBindingEvent extends DhApiLevelLoadEvent
|
||||
{
|
||||
private static final Logger LOGGER = DhLoggerBuilder.getLogger();
|
||||
private static final org.slf4j.Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
@Override
|
||||
public void onLevelLoad(DhApiEventParam<DhApiLevelLoadEvent.EventParam> event)
|
||||
|
||||
+4
-36
@@ -9,27 +9,18 @@ import com.seibel.distanthorizons.api.interfaces.override.worldGenerator.Abstrac
|
||||
import com.seibel.distanthorizons.api.interfaces.world.IDhApiLevelWrapper;
|
||||
import com.seibel.distanthorizons.api.objects.data.DhApiChunk;
|
||||
import com.seibel.distanthorizons.api.objects.data.DhApiTerrainDataPoint;
|
||||
import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper;
|
||||
import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper;
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class TestWorldGenerator extends AbstractDhApiChunkWorldGenerator
|
||||
{
|
||||
private final ServerLevel level;
|
||||
private final IDhApiLevelWrapper levelWrapper;
|
||||
|
||||
|
||||
|
||||
//=============//
|
||||
// constructor //
|
||||
//=============//
|
||||
|
||||
public TestWorldGenerator(ServerLevel level)
|
||||
{
|
||||
this.level = level;
|
||||
@@ -37,23 +28,13 @@ public class TestWorldGenerator extends AbstractDhApiChunkWorldGenerator
|
||||
}
|
||||
|
||||
|
||||
|
||||
//============//
|
||||
// properties //
|
||||
//============//
|
||||
|
||||
@Override
|
||||
public EDhApiWorldGeneratorReturnType getReturnType() { return EDhApiWorldGeneratorReturnType.API_CHUNKS; }
|
||||
|
||||
@Override
|
||||
public boolean runApiChunkValidation() { return true; }
|
||||
@Override
|
||||
public boolean isBusy() { return false; }
|
||||
|
||||
|
||||
|
||||
//==================//
|
||||
// chunk generation //
|
||||
//==================//
|
||||
|
||||
@Override
|
||||
public Object[] generateChunk(int chunkX, int chunkZ, EDhApiDistantGeneratorMode eDhApiDistantGeneratorMode)
|
||||
{
|
||||
@@ -64,14 +45,10 @@ public class TestWorldGenerator extends AbstractDhApiChunkWorldGenerator
|
||||
@Override
|
||||
public DhApiChunk generateApiChunk(int chunkPosX, int chunkPosZ, EDhApiDistantGeneratorMode generatorMode)
|
||||
{
|
||||
// this test is only validated for 1.18.2 and up
|
||||
// (and it is only needed when testing world gen overrides/API chunks, so it isn't normally needed)
|
||||
#if MC_VER >= MC_1_18_2
|
||||
ChunkAccess chunk = this.level.getChunk(chunkPosX, chunkPosZ);
|
||||
|
||||
|
||||
int minBuildHeight = this.level.getMinBuildHeight();
|
||||
int maxBuildHeight = this.level.getMaxBuildHeight();
|
||||
int minBuildHeight = chunk.getMinBuildHeight();
|
||||
int maxBuildHeight = chunk.getMaxBuildHeight();
|
||||
|
||||
DhApiChunk apiChunk = DhApiChunk.create(chunkPosX, chunkPosZ, minBuildHeight, maxBuildHeight);
|
||||
for (int x = 0; x < 16; x++)
|
||||
@@ -94,20 +71,11 @@ public class TestWorldGenerator extends AbstractDhApiChunkWorldGenerator
|
||||
}
|
||||
}
|
||||
return apiChunk;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preGeneratorTaskStart() { /* do nothing */ }
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// cleanup //
|
||||
//=========//
|
||||
|
||||
@Override
|
||||
public void close() { /* do nothing */ }
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IBCLibAcces
|
||||
#elif MC_VER == MC_1_18_2
|
||||
import ru.bclib.config.ClientConfig;
|
||||
import ru.bclib.config.Configs;
|
||||
#elif MC_VER < MC_1_21_1
|
||||
#elif MC_VER < MC_1_21
|
||||
import org.betterx.bclib.config.ClientConfig;
|
||||
import org.betterx.bclib.config.Configs;
|
||||
#endif
|
||||
|
||||
@@ -5,18 +5,12 @@
|
||||
"mixins": [
|
||||
"server.MixinChunkGenerator",
|
||||
"server.MixinChunkMap",
|
||||
"server.MixinUtilBackgroundThread",
|
||||
"server.MixinServerPlayer",
|
||||
"server.MixinEntity"
|
||||
"server.MixinUtilBackgroundThread"
|
||||
],
|
||||
"client": [
|
||||
"client.MixinClientLevel",
|
||||
"client.MixinClientPacketListener",
|
||||
"client.MixinDebugScreenOverlay",
|
||||
"client.MixinFogRenderer",
|
||||
"client.MixinGameRenderer",
|
||||
"client.MixinLevelRenderer",
|
||||
"client.MixinLightTexture",
|
||||
"client.MixinOptionsScreen",
|
||||
"client.MixinMinecraft",
|
||||
"client.MixinTextureUtil"
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
},
|
||||
|
||||
"mixins": [
|
||||
"DistantHorizons.common.mixins.json",
|
||||
"DistantHorizons.fabric.mixins.json"
|
||||
],
|
||||
|
||||
|
||||
+6
-7
@@ -28,6 +28,7 @@ loom {
|
||||
extraAccessWideners.add loom.accessWidenerPath.get().asFile.name
|
||||
|
||||
mixinConfigs = [
|
||||
"DistantHorizons.common.mixins.json",
|
||||
"DistantHorizons.forge.mixins.json"
|
||||
]
|
||||
}
|
||||
@@ -37,17 +38,15 @@ loom {
|
||||
client {
|
||||
client()
|
||||
setConfigName("Forge Client")
|
||||
ideConfigGenerated(false) // When true a run configuration file will be generated for IDE's. By default only set to true for the root project.
|
||||
runDir("../run/client")
|
||||
vmArgs("-Dio.netty.leakDetection.level=advanced") // https://netty.io/wiki/reference-counted-objects.html#leak-detection-levels
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -170,59 +176,53 @@ public class ForgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
@SubscribeEvent
|
||||
public void rightClickBlockEvent(PlayerInteractEvent.RightClickBlock event)
|
||||
{
|
||||
if (MC.clientConnectedToDedicatedServer())
|
||||
if (SharedApi.isChunkAtBlockPosAlreadyUpdating(event.getPos().getX(), event.getPos().getZ()))
|
||||
{
|
||||
if (SharedApi.isChunkAtBlockPosAlreadyUpdating(event.getPos().getX(), event.getPos().getZ()))
|
||||
return;
|
||||
}
|
||||
|
||||
//LOGGER.trace("interact or block place event at blockPos: " + event.getPos());
|
||||
|
||||
#if MC_VER < MC_1_19_2
|
||||
LevelAccessor level = event.getWorld();
|
||||
#else
|
||||
LevelAccessor level = event.getLevel();
|
||||
#endif
|
||||
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getFileHandlerExecutor();
|
||||
if (executor != null)
|
||||
{
|
||||
executor.execute(() ->
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//LOGGER.trace("interact or block place event at blockPos: " + event.getPos());
|
||||
|
||||
#if MC_VER < MC_1_19_2
|
||||
LevelAccessor level = event.getWorld();
|
||||
#else
|
||||
LevelAccessor level = event.getLevel();
|
||||
#endif
|
||||
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getFileHandlerExecutor();
|
||||
if (executor != null)
|
||||
{
|
||||
executor.execute(() ->
|
||||
{
|
||||
ChunkAccess chunk = level.getChunk(event.getPos());
|
||||
this.onBlockChangeEvent(level, chunk);
|
||||
});
|
||||
}
|
||||
ChunkAccess chunk = level.getChunk(event.getPos());
|
||||
this.onBlockChangeEvent(level, chunk);
|
||||
});
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void leftClickBlockEvent(PlayerInteractEvent.LeftClickBlock event)
|
||||
{
|
||||
if (MC.clientConnectedToDedicatedServer())
|
||||
if (SharedApi.isChunkAtBlockPosAlreadyUpdating(event.getPos().getX(), event.getPos().getZ()))
|
||||
{
|
||||
if (SharedApi.isChunkAtBlockPosAlreadyUpdating(event.getPos().getX(), event.getPos().getZ()))
|
||||
return;
|
||||
}
|
||||
|
||||
//LOGGER.trace("break or block attack at blockPos: " + event.getPos());
|
||||
|
||||
#if MC_VER < MC_1_19_2
|
||||
LevelAccessor level = event.getWorld();
|
||||
#else
|
||||
LevelAccessor level = event.getLevel();
|
||||
#endif
|
||||
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getFileHandlerExecutor();
|
||||
if (executor != null)
|
||||
{
|
||||
executor.execute(() ->
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//LOGGER.trace("break or block attack at blockPos: " + event.getPos());
|
||||
|
||||
#if MC_VER < MC_1_19_2
|
||||
LevelAccessor level = event.getWorld();
|
||||
#else
|
||||
LevelAccessor level = event.getLevel();
|
||||
#endif
|
||||
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getFileHandlerExecutor();
|
||||
if (executor != null)
|
||||
{
|
||||
executor.execute(() ->
|
||||
{
|
||||
ChunkAccess chunk = level.getChunk(event.getPos());
|
||||
this.onBlockChangeEvent(level, chunk);
|
||||
});
|
||||
}
|
||||
ChunkAccess chunk = level.getChunk(event.getPos());
|
||||
this.onBlockChangeEvent(level, chunk);
|
||||
});
|
||||
}
|
||||
}
|
||||
private void onBlockChangeEvent(LevelAccessor level, ChunkAccess chunk)
|
||||
@@ -230,16 +230,21 @@ public class ForgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
ILevelWrapper wrappedLevel = ProxyUtil.getLevelWrapper(level);
|
||||
SharedApi.INSTANCE.chunkBlockChangedEvent(new ChunkWrapper(chunk, level, wrappedLevel), wrappedLevel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void clientChunkLoadEvent(ChunkEvent.Load event)
|
||||
{
|
||||
if (MC.clientConnectedToDedicatedServer())
|
||||
{
|
||||
ILevelWrapper wrappedLevel = ProxyUtil.getLevelWrapper(GetEventLevel(event));
|
||||
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetEventLevel(event), wrappedLevel);
|
||||
SharedApi.INSTANCE.chunkLoadEvent(chunk, wrappedLevel);
|
||||
}
|
||||
ILevelWrapper wrappedLevel = ProxyUtil.getLevelWrapper(GetEventLevel(event));
|
||||
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetEventLevel(event), wrappedLevel);
|
||||
SharedApi.INSTANCE.chunkLoadEvent(chunk, wrappedLevel);
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void clientChunkUnloadEvent(ChunkEvent.Unload event)
|
||||
{
|
||||
ILevelWrapper wrappedLevel = ProxyUtil.getLevelWrapper(GetEventLevel(event));
|
||||
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetEventLevel(event), wrappedLevel);
|
||||
SharedApi.INSTANCE.chunkUnloadEvent(chunk, wrappedLevel);
|
||||
}
|
||||
|
||||
|
||||
@@ -264,6 +269,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 //
|
||||
//===========//
|
||||
|
||||
@@ -22,11 +22,7 @@ package com.seibel.distanthorizons.forge;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
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.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 +34,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 +81,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(); }
|
||||
@@ -113,20 +104,6 @@ public class ForgeMain extends AbstractModInitializer
|
||||
ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class,
|
||||
() -> new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> GetConfigScreen.getScreen(parent)));
|
||||
#endif
|
||||
|
||||
|
||||
if (Config.Client.Advanced.Logging.showModCompatibilityWarningsOnStartup.get())
|
||||
{
|
||||
IModChecker modChecker = SingletonInjector.INSTANCE.get(IModChecker.class);
|
||||
if (modChecker.isModLoaded("alexscaves"))
|
||||
{
|
||||
String message =
|
||||
// orange text
|
||||
"\u00A76" + "Distant Horizons: Alex's Cave detected." + "\u00A7r\n" +
|
||||
"You may have to change Alex's config for DH to render. ";
|
||||
ClientApi.INSTANCE.showChatMessageNextFrame(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,7 +121,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());
|
||||
});
|
||||
|
||||
@@ -1,127 +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.AbstractNetworkMessage;
|
||||
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<AbstractNetworkMessage> consumer)
|
||||
{
|
||||
setPacketHandler((player, message) -> consumer.accept(message));
|
||||
}
|
||||
public static void setPacketHandler(BiConsumer<IServerPlayerWrapper, AbstractNetworkMessage> 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 sendToServer(AbstractNetworkMessage 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 sendToClient(ServerPlayer serverPlayer, AbstractNetworkMessage 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 AbstractNetworkMessage message;
|
||||
|
||||
public MessageWrapper(AbstractNetworkMessage 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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,21 +137,13 @@ public class ForgeServerProxy implements AbstractModInitializer.IEventProxy
|
||||
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetEventLevel(event), levelWrapper);
|
||||
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)
|
||||
public void serverChunkSaveEvent(ChunkEvent.Unload event)
|
||||
{
|
||||
this.serverApi.serverPlayerLevelChangeEvent(
|
||||
getServerPlayerWrapper(event),
|
||||
getServerLevelWrapper(event.getFrom(), event),
|
||||
getServerLevelWrapper(event.getTo(), event)
|
||||
);
|
||||
ILevelWrapper levelWrapper = ProxyUtil.getLevelWrapper(GetEventLevel(event));
|
||||
|
||||
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetEventLevel(event), levelWrapper);
|
||||
this.serverApi.serverChunkSaveEvent(chunk, levelWrapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -177,20 +155,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
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-84
@@ -1,84 +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.client;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.client.renderer.FogRenderer.FogMode;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
#if MC_VER < MC_1_17_1
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
#else
|
||||
import net.minecraft.world.level.material.FogType;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@Mixin(FogRenderer.class)
|
||||
public class MixinFogRenderer
|
||||
{
|
||||
|
||||
// Using this instead of Float.MAX_VALUE because Sodium don't like it.
|
||||
private static final float A_REALLY_REALLY_BIG_VALUE = 420694206942069.F;
|
||||
private static final float A_EVEN_LARGER_VALUE = 42069420694206942069.F;
|
||||
|
||||
@Inject(at = @At("RETURN"),
|
||||
method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V",
|
||||
remap = #if MC_VER == MC_1_17_1 || MC_VER == MC_1_18_2 false #else true #endif ) // Remap messiness due to this being weird in forge
|
||||
private static void disableSetupFog(Camera camera, FogMode fogMode, float f, boolean bl, float partTick, CallbackInfo callback)
|
||||
{
|
||||
#if MC_VER < MC_1_17_1
|
||||
FluidState fluidState = camera.getFluidInCamera();
|
||||
boolean cameraNotInFluid = fluidState.isEmpty();
|
||||
#else
|
||||
FogType fogTypes = camera.getFluidInCamera();
|
||||
boolean cameraNotInFluid = fogTypes == FogType.NONE;
|
||||
#endif
|
||||
|
||||
|
||||
Entity entity = camera.getEntity();
|
||||
boolean isSpecialFog = (entity instanceof LivingEntity) && ((LivingEntity) entity).hasEffect(MobEffects.BLINDNESS);
|
||||
if (!isSpecialFog && cameraNotInFluid && fogMode == FogMode.FOG_TERRAIN
|
||||
&& !SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class).isFogStateSpecial()
|
||||
&& Config.Client.Advanced.Graphics.Fog.disableVanillaFog.get())
|
||||
{
|
||||
#if MC_VER < MC_1_17_1
|
||||
RenderSystem.fogStart(A_REALLY_REALLY_BIG_VALUE);
|
||||
RenderSystem.fogEnd(A_EVEN_LARGER_VALUE);
|
||||
#else
|
||||
RenderSystem.setShaderFogStart(A_REALLY_REALLY_BIG_VALUE);
|
||||
RenderSystem.setShaderFogEnd(A_EVEN_LARGER_VALUE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
package com.seibel.distanthorizons.forge.mixins.client;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.DependencySetupDoneCheck;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
// TODO: Check if this port from fabric works
|
||||
@Mixin(GameRenderer.class)
|
||||
public class MixinGameRenderer
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger(MixinGameRenderer.class.getSimpleName());
|
||||
|
||||
#if MC_VER >= MC_1_17_1
|
||||
// FIXME: This I think will dup multiple renderStartupEvent calls...
|
||||
@Inject(method = {"reloadShaders", "preloadUiShader"}, at = @At("TAIL"))
|
||||
public void onStartupShaders(CallbackInfo ci)
|
||||
{
|
||||
LOGGER.info("Starting up renderer (forge)");
|
||||
if (!DependencySetupDoneCheck.isDone)
|
||||
{
|
||||
LOGGER.warn("Dependency setup is not done yet, skipping renderer this startup event!");
|
||||
return;
|
||||
}
|
||||
ClientApi.INSTANCE.rendererStartupEvent();
|
||||
}
|
||||
|
||||
@Inject(method = "shutdownShaders", at = @At("HEAD"))
|
||||
public void onShutdownShaders(CallbackInfo ci)
|
||||
{
|
||||
LOGGER.info("Shutting down renderer (forge)");
|
||||
if (!DependencySetupDoneCheck.isDone)
|
||||
{
|
||||
LOGGER.warn("Dependency setup is not done yet, skipping renderer this shutdown event!");
|
||||
return;
|
||||
}
|
||||
ClientApi.INSTANCE.rendererShutdownEvent();
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
@Inject(method = {"loadEffect"}, at = @At("TAIL"))
|
||||
public void onStartupShaders(CallbackInfo ci) {
|
||||
ClientApi.INSTANCE.rendererStartupEvent();
|
||||
}
|
||||
|
||||
@Inject(method = "shutdownEffect", at = @At("HEAD"))
|
||||
public void onShutdownShaders(CallbackInfo ci) {
|
||||
ClientApi.INSTANCE.rendererShutdownEvent();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
+14
@@ -158,4 +158,18 @@ public class MixinLevelRenderer
|
||||
}
|
||||
}
|
||||
|
||||
#if MC_VER < MC_1_19_4
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runUpdates(IZZ)I"), method = "renderLevel")
|
||||
public void callAfterRunUpdates(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci)
|
||||
#elif MC_VER < MC_1_20_1
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runUpdates(IZZ)I"), method = "renderLevel")
|
||||
public void callAfterRunUpdates(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci)
|
||||
#else
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I"), method = "renderLevel")
|
||||
private void callAfterRunUpdates(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci)
|
||||
#endif
|
||||
{
|
||||
ChunkWrapper.syncedUpdateClientLightStatus();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-59
@@ -1,59 +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.client;
|
||||
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LightTexture.class)
|
||||
public class MixinLightTexture
|
||||
{
|
||||
@Shadow //# if MC_VER >= MC_1_20_4 (remap = false) # endif
|
||||
@Final
|
||||
private NativeImage lightPixels;
|
||||
|
||||
|
||||
@Inject(method = "updateLightTexture(F)V", at = @At("RETURN"))
|
||||
public void updateLightTexture(float partialTicks, CallbackInfo ci)
|
||||
{
|
||||
IMinecraftClientWrapper mc = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
if (mc == null || mc.getWrappedClientLevel() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IClientLevelWrapper clientLevel = mc.getWrappedClientLevel();
|
||||
MinecraftRenderWrapper.INSTANCE.updateLightmap(this.lightPixels, clientLevel);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.seibel.distanthorizons.forge.mixins.server;
|
||||
|
||||
import com.seibel.distanthorizons.common.commonMixins.MixinChunkMapCommon;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ChunkMap.class)
|
||||
public class MixinChunkMap
|
||||
{
|
||||
|
||||
@Unique
|
||||
private static final String CHUNK_SERIALIZER_WRITE
|
||||
= "Lnet/minecraft/world/level/chunk/storage/ChunkSerializer;write(" +
|
||||
"Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/chunk/ChunkAccess;)" +
|
||||
"Lnet/minecraft/nbt/CompoundTag;";
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
ServerLevel level;
|
||||
|
||||
// firing at INVOKE causes issues with C2ME and is probably unnecessary since we
|
||||
// don't need the chunk(s) before MC has finished saving them
|
||||
@Inject(method = "save", at = @At(value = "RETURN", target = CHUNK_SERIALIZER_WRITE))
|
||||
private void onChunkSave(ChunkAccess chunk, CallbackInfoReturnable<Boolean> ci)
|
||||
{ MixinChunkMapCommon.onChunkSave(this.level, chunk, ci); }
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#if MC_VER == MC_1_16_5
|
||||
|
||||
package com.seibel.distanthorizons.forge.mixins.server;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.misc.IMixinServerPlayer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public class MixinEntity
|
||||
{
|
||||
@Inject(at = @At("TAIL"), method = "setLevel")
|
||||
public void setLevel(Level level, CallbackInfo ci)
|
||||
{
|
||||
if (this instanceof IMixinServerPlayer)
|
||||
{
|
||||
((IMixinServerPlayer) this).distantHorizons$setDimensionChangeDestination((ServerLevel) level);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
package com.seibel.distanthorizons.forge.mixins.server;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(Entity.class)
|
||||
public class MixinEntity
|
||||
{
|
||||
}
|
||||
#endif
|
||||
-68
@@ -1,68 +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; }
|
||||
|
||||
#if MC_VER == MC_1_16_5
|
||||
@Override
|
||||
public void distantHorizons$setDimensionChangeDestination(ServerLevel dimensionChangeDestination)
|
||||
{ this.distantHorizons$dimensionChangeDestination = dimensionChangeDestination; }
|
||||
#endif
|
||||
|
||||
@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)
|
||||
{ this.distantHorizons$dimensionChangeDestination = null; }
|
||||
#elif MC_VER >= MC_1_17_1
|
||||
@Inject(at = @At("RETURN"), method = "setLevel")
|
||||
public void setLevel(ServerLevel level, CallbackInfo ci)
|
||||
{ this.distantHorizons$dimensionChangeDestination = null; }
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -5,18 +5,11 @@
|
||||
"mixins": [
|
||||
"server.MixinUtilBackgroundThread",
|
||||
"server.MixinChunkGenerator",
|
||||
"server.MixinTFChunkGenerator",
|
||||
"server.MixinChunkMap",
|
||||
"server.MixinServerPlayer",
|
||||
"server.MixinEntity"
|
||||
"server.MixinTFChunkGenerator"
|
||||
],
|
||||
"client": [
|
||||
"client.MixinClientPacketListener",
|
||||
"client.MixinDebugScreenOverlay",
|
||||
"client.MixinFogRenderer",
|
||||
"client.MixinGameRenderer",
|
||||
"client.MixinLevelRenderer",
|
||||
"client.MixinLightTexture",
|
||||
"client.MixinOptionsScreen",
|
||||
"client.MixinTextureUtil"
|
||||
],
|
||||
|
||||
+4
-3
@@ -5,8 +5,8 @@ org.gradle.caching=true
|
||||
|
||||
# Mod Info
|
||||
mod_name=DistantHorizons
|
||||
mod_version=2.3.0-a-dev
|
||||
api_version=4.0.0
|
||||
mod_version=2.1.3-a-dev
|
||||
api_version=3.0.0
|
||||
maven_group=com.seibel.distanthorizons
|
||||
mod_readable_name=Distant Horizons
|
||||
mod_description=This mod generates and renders simplified terrain beyond the normal view distance at a low performance cost. Allowing you to see much farther without turning your game into a slideshow.
|
||||
@@ -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
|
||||
|
||||
@@ -48,7 +49,7 @@ versionStr=
|
||||
|
||||
# This defines what MC version Intellij will use for the preprocessor
|
||||
# and what version is used automatically by build and run commands
|
||||
mcVer=1.21.1
|
||||
mcVer=1.21
|
||||
|
||||
# Defines the maximum amount of memory Minecraft is allowed when run in a development environment
|
||||
#minecraftMemoryJavaArg="-Xmx4G"
|
||||
|
||||
@@ -29,17 +29,15 @@ loom {
|
||||
client {
|
||||
client()
|
||||
setConfigName("NeoForge Client")
|
||||
ideConfigGenerated(false) // When true a run configuration file will be generated for IDE's. By default only set to true for the root project.
|
||||
runDir("../run/client")
|
||||
vmArgs("-Dio.netty.leakDetection.level=advanced") // https://netty.io/wiki/reference-counted-objects.html#leak-detection-levels
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+118
-44
@@ -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;
|
||||
|
||||
@@ -60,8 +63,6 @@ import org.lwjgl.opengl.GL32;
|
||||
import net.neoforged.neoforge.event.TickEvent;
|
||||
#else
|
||||
import net.neoforged.neoforge.client.event.ClientTickEvent;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -87,7 +88,11 @@ public class NeoforgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
|
||||
|
||||
@Override
|
||||
public void registerEvents() { NeoForge.EVENT_BUS.register(this); }
|
||||
public void registerEvents()
|
||||
{
|
||||
NeoForge.EVENT_BUS.register(this);
|
||||
setupNetworkingListeners();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -130,7 +135,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);
|
||||
}
|
||||
@@ -159,55 +164,49 @@ public class NeoforgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
@SubscribeEvent
|
||||
public void rightClickBlockEvent(PlayerInteractEvent.RightClickBlock event)
|
||||
{
|
||||
if (MC.clientConnectedToDedicatedServer())
|
||||
if (SharedApi.isChunkAtBlockPosAlreadyUpdating(event.getPos().getX(), event.getPos().getZ()))
|
||||
{
|
||||
if (SharedApi.isChunkAtBlockPosAlreadyUpdating(event.getPos().getX(), event.getPos().getZ()))
|
||||
return;
|
||||
}
|
||||
|
||||
// executor to prevent locking up the render/event thread
|
||||
// if the getChunk() takes longer than expected
|
||||
// (which can be caused by certain mods)
|
||||
var executor = ThreadPoolUtil.getFileHandlerExecutor();
|
||||
if (executor != null)
|
||||
{
|
||||
executor.execute(() ->
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// executor to prevent locking up the render/event thread
|
||||
// if the getChunk() takes longer than expected
|
||||
// (which can be caused by certain mods)
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getFileHandlerExecutor();
|
||||
if (executor != null)
|
||||
{
|
||||
executor.execute(() ->
|
||||
{
|
||||
//LOGGER.trace("interact or block place event at blockPos: " + event.getPos());
|
||||
|
||||
LevelAccessor level = event.getLevel();
|
||||
ChunkAccess chunk = level.getChunk(event.getPos());
|
||||
this.onBlockChangeEvent(level, chunk);
|
||||
});
|
||||
}
|
||||
//LOGGER.trace("interact or block place event at blockPos: " + event.getPos());
|
||||
|
||||
LevelAccessor level = event.getLevel();
|
||||
ChunkAccess chunk = level.getChunk(event.getPos());
|
||||
this.onBlockChangeEvent(level, chunk);
|
||||
});
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void leftClickBlockEvent(PlayerInteractEvent.LeftClickBlock event)
|
||||
{
|
||||
if (MC.clientConnectedToDedicatedServer())
|
||||
if (SharedApi.isChunkAtBlockPosAlreadyUpdating(event.getPos().getX(), event.getPos().getZ()))
|
||||
{
|
||||
if (SharedApi.isChunkAtBlockPosAlreadyUpdating(event.getPos().getX(), event.getPos().getZ()))
|
||||
return;
|
||||
}
|
||||
|
||||
// executor to prevent locking up the render/event thread
|
||||
// if the getChunk() takes longer than expected
|
||||
// (which can be caused by certain mods)
|
||||
var executor = ThreadPoolUtil.getFileHandlerExecutor();
|
||||
if (executor != null)
|
||||
{
|
||||
executor.execute(() ->
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// executor to prevent locking up the render/event thread
|
||||
// if the getChunk() takes longer than expected
|
||||
// (which can be caused by certain mods)
|
||||
ThreadPoolExecutor executor = ThreadPoolUtil.getFileHandlerExecutor();
|
||||
if (executor != null)
|
||||
{
|
||||
executor.execute(() ->
|
||||
{
|
||||
//LOGGER.trace("break or block attack at blockPos: " + event.getPos());
|
||||
|
||||
LevelAccessor level = event.getLevel();
|
||||
ChunkAccess chunk = level.getChunk(event.getPos());
|
||||
this.onBlockChangeEvent(level, chunk);
|
||||
});
|
||||
}
|
||||
//LOGGER.trace("break or block attack at blockPos: " + event.getPos());
|
||||
|
||||
LevelAccessor level = event.getLevel();
|
||||
ChunkAccess chunk = level.getChunk(event.getPos());
|
||||
this.onBlockChangeEvent(level, chunk);
|
||||
});
|
||||
}
|
||||
}
|
||||
private void onBlockChangeEvent(LevelAccessor level, ChunkAccess chunk)
|
||||
@@ -217,6 +216,22 @@ public class NeoforgeClientProxy implements AbstractModInitializer.IEventProxy
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void clientChunkLoadEvent(ChunkEvent.Load event)
|
||||
{
|
||||
ILevelWrapper wrappedLevel = ProxyUtil.getLevelWrapper(GetEventLevel(event));
|
||||
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetEventLevel(event), wrappedLevel);
|
||||
SharedApi.INSTANCE.chunkLoadEvent(chunk, wrappedLevel);
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void clientChunkUnloadEvent(ChunkEvent.Unload event)
|
||||
{
|
||||
ILevelWrapper wrappedLevel = ProxyUtil.getLevelWrapper(GetEventLevel(event));
|
||||
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetEventLevel(event), wrappedLevel);
|
||||
SharedApi.INSTANCE.chunkUnloadEvent(chunk, wrappedLevel);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// key bindings //
|
||||
@@ -239,6 +254,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 //
|
||||
//===========//
|
||||
|
||||
@@ -22,11 +22,7 @@ package com.seibel.distanthorizons.neoforge;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
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 +30,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 +38,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,42 +53,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(); }
|
||||
@@ -112,20 +83,6 @@ public class NeoforgeMain extends AbstractModInitializer
|
||||
// TODO fix potential null pointer
|
||||
() -> (client, parent) -> GetConfigScreen.getScreen(parent));
|
||||
#endif
|
||||
|
||||
|
||||
if (Config.Client.Advanced.Logging.showModCompatibilityWarningsOnStartup.get())
|
||||
{
|
||||
IModChecker modChecker = SingletonInjector.INSTANCE.get(IModChecker.class);
|
||||
if (modChecker.isModLoaded("alexscaves"))
|
||||
{
|
||||
String message =
|
||||
// orange text
|
||||
"\u00A76" + "Distant Horizons: Alex's Cave detected." + "\u00A7r\n" +
|
||||
"You may have to change Alex's config for DH to render. ";
|
||||
ClientApi.INSTANCE.showChatMessageNextFrame(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -143,7 +100,7 @@ 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
|
||||
|
||||
-50
@@ -1,50 +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.AbstractNetworkMessage;
|
||||
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, AbstractNetworkMessage> packetConsumer;
|
||||
|
||||
public static void setPacketHandler(RegisterPayloadHandlersEvent event, Consumer<AbstractNetworkMessage> consumer)
|
||||
{ setPacketHandler(event, (player, buffer) -> consumer.accept(buffer)); }
|
||||
public static void setPacketHandler(RegisterPayloadHandlersEvent event, BiConsumer<IServerPlayerWrapper, AbstractNetworkMessage> 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 sendToServer(AbstractNetworkMessage message)
|
||||
{ PacketDistributor.sendToServer(new CommonPacketPayload(message)); }
|
||||
|
||||
@Override
|
||||
public void sendToClient(ServerPlayer serverPlayer, AbstractNetworkMessage message)
|
||||
{ PacketDistributor.sendToPlayer(serverPlayer, new CommonPacketPayload(message)); }
|
||||
|
||||
}
|
||||
+5
-23
@@ -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;
|
||||
@@ -127,20 +122,13 @@ public class NeoforgeServerProxy implements AbstractModInitializer.IEventProxy
|
||||
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetEventLevel(event), levelWrapper);
|
||||
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)
|
||||
public void serverChunkSaveEvent(ChunkEvent.Unload event)
|
||||
{
|
||||
this.serverApi.serverPlayerLevelChangeEvent(
|
||||
getServerPlayerWrapper(event),
|
||||
getServerLevelWrapper(event.getFrom(), event),
|
||||
getServerLevelWrapper(event.getTo(), event)
|
||||
);
|
||||
ILevelWrapper levelWrapper = ProxyUtil.getLevelWrapper(GetEventLevel(event));
|
||||
|
||||
IChunkWrapper chunk = new ChunkWrapper(event.getChunk(), GetEventLevel(event), levelWrapper);
|
||||
this.serverApi.serverChunkSaveEvent(chunk, levelWrapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -150,12 +138,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"))
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.seibel.distanthorizons.neoforge.mixins.client;
|
||||
|
||||
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
|
||||
import net.minecraft.client.gui.components.DebugScreenOverlay;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(DebugScreenOverlay.class)
|
||||
public class MixinDebugScreenOverlay
|
||||
{
|
||||
|
||||
@Inject(method = "getSystemInformation", at = @At("RETURN"))
|
||||
private void addCustomF3(CallbackInfoReturnable<List<String>> cir)
|
||||
{
|
||||
List<String> messages = cir.getReturnValue();
|
||||
F3Screen.addStringToDisplay(messages);
|
||||
}
|
||||
|
||||
}
|
||||
-84
@@ -1,84 +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.client;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraft.client.renderer.FogRenderer.FogMode;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
#if MC_VER < MC_1_17_1
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
#else
|
||||
import net.minecraft.world.level.material.FogType;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@Mixin(FogRenderer.class)
|
||||
public class MixinFogRenderer
|
||||
{
|
||||
|
||||
// Using this instead of Float.MAX_VALUE because Sodium don't like it.
|
||||
private static final float A_REALLY_REALLY_BIG_VALUE = 420694206942069.F;
|
||||
private static final float A_EVEN_LARGER_VALUE = 42069420694206942069.F;
|
||||
|
||||
@Inject(at = @At("RETURN"),
|
||||
method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V",
|
||||
remap = #if MC_VER == MC_1_17_1 || MC_VER == MC_1_18_2 false #else true #endif ) // Remap messiness due to this being weird in forge
|
||||
private static void disableSetupFog(Camera camera, FogMode fogMode, float f, boolean bl, float partTick, CallbackInfo callback)
|
||||
{
|
||||
#if MC_VER < MC_1_17_1
|
||||
FluidState fluidState = camera.getFluidInCamera();
|
||||
boolean cameraNotInFluid = fluidState.isEmpty();
|
||||
#else
|
||||
FogType fogTypes = camera.getFluidInCamera();
|
||||
boolean cameraNotInFluid = fogTypes == FogType.NONE;
|
||||
#endif
|
||||
|
||||
|
||||
Entity entity = camera.getEntity();
|
||||
boolean isSpecialFog = (entity instanceof LivingEntity) && ((LivingEntity) entity).hasEffect(MobEffects.BLINDNESS);
|
||||
if (!isSpecialFog && cameraNotInFluid && fogMode == FogMode.FOG_TERRAIN
|
||||
&& !SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class).isFogStateSpecial()
|
||||
&& Config.Client.Advanced.Graphics.Fog.disableVanillaFog.get())
|
||||
{
|
||||
#if MC_VER < MC_1_17_1
|
||||
RenderSystem.fogStart(A_REALLY_REALLY_BIG_VALUE);
|
||||
RenderSystem.fogEnd(A_EVEN_LARGER_VALUE);
|
||||
#else
|
||||
RenderSystem.setShaderFogStart(A_REALLY_REALLY_BIG_VALUE);
|
||||
RenderSystem.setShaderFogEnd(A_EVEN_LARGER_VALUE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
package com.seibel.distanthorizons.neoforge.mixins.client;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.DependencySetupDoneCheck;
|
||||
import com.seibel.distanthorizons.core.api.internal.ClientApi;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
// TODO: Check if this port from fabric works
|
||||
@Mixin(GameRenderer.class)
|
||||
public class MixinGameRenderer
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger(MixinGameRenderer.class.getSimpleName());
|
||||
|
||||
#if MC_VER >= MC_1_17_1
|
||||
// FIXME: This I think will dup multiple renderStartupEvent calls...
|
||||
@Inject(method = {"reloadShaders", "preloadUiShader"}, at = @At("TAIL"))
|
||||
public void onStartupShaders(CallbackInfo ci)
|
||||
{
|
||||
LOGGER.info("Starting up renderer (forge)");
|
||||
if (!DependencySetupDoneCheck.isDone)
|
||||
{
|
||||
LOGGER.warn("Dependency setup is not done yet, skipping renderer this startup event!");
|
||||
return;
|
||||
}
|
||||
ClientApi.INSTANCE.rendererStartupEvent();
|
||||
}
|
||||
|
||||
@Inject(method = "shutdownShaders", at = @At("HEAD"))
|
||||
public void onShutdownShaders(CallbackInfo ci)
|
||||
{
|
||||
LOGGER.info("Shutting down renderer (forge)");
|
||||
if (!DependencySetupDoneCheck.isDone)
|
||||
{
|
||||
LOGGER.warn("Dependency setup is not done yet, skipping renderer this shutdown event!");
|
||||
return;
|
||||
}
|
||||
ClientApi.INSTANCE.rendererShutdownEvent();
|
||||
}
|
||||
#else
|
||||
|
||||
|
||||
@Inject(method = {"loadEffect"}, at = @At("TAIL"))
|
||||
public void onStartupShaders(CallbackInfo ci) {
|
||||
ClientApi.INSTANCE.rendererStartupEvent();
|
||||
}
|
||||
|
||||
@Inject(method = "shutdownEffect", at = @At("HEAD"))
|
||||
public void onShutdownShaders(CallbackInfo ci) {
|
||||
ClientApi.INSTANCE.rendererShutdownEvent();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
+18
-1
@@ -120,7 +120,7 @@ public class MixinLevelRenderer
|
||||
|
||||
|
||||
float frameTime;
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
frameTime = Minecraft.getInstance().getFrameTime();
|
||||
#else
|
||||
frameTime = Minecraft.getInstance().getTimer().getRealtimeDeltaTicks();
|
||||
@@ -142,5 +142,22 @@ public class MixinLevelRenderer
|
||||
}
|
||||
}
|
||||
|
||||
#if MC_VER < MC_1_19_4
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runUpdates(IZZ)I"), method = "renderLevel")
|
||||
public void callAfterRunUpdates(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci)
|
||||
#elif MC_VER < MC_1_20_1
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runUpdates(IZZ)I"), method = "renderLevel")
|
||||
public void callAfterRunUpdates(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci)
|
||||
#elif MC_VER < MC_1_20_6
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I"), method = "renderLevel")
|
||||
private void callAfterRunUpdates(PoseStack poseStack, float partialTick, long finishNanoTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightTexture lightTexture, Matrix4f projectionMatrix, CallbackInfo ci)
|
||||
#else
|
||||
@Inject(at = @At(value = "TAIL", target = "Lnet/minecraft/world/level/lighting/LevelLightEngine;runLightUpdates()I"), method = "renderLevel")
|
||||
private void callAfterRunUpdates(CallbackInfo ci)
|
||||
#endif
|
||||
{
|
||||
ChunkWrapper.syncedUpdateClientLightStatus();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
-59
@@ -1,59 +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.client;
|
||||
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
|
||||
import com.seibel.distanthorizons.common.wrappers.minecraft.MinecraftRenderWrapper;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LightTexture.class)
|
||||
public class MixinLightTexture
|
||||
{
|
||||
@Shadow
|
||||
@Final
|
||||
private NativeImage lightPixels;
|
||||
|
||||
|
||||
@Inject(method = "updateLightTexture(F)V", at = @At("RETURN"))
|
||||
public void updateLightTexture(float partialTicks, CallbackInfo ci)
|
||||
{
|
||||
IMinecraftClientWrapper mc = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
|
||||
if (mc == null || mc.getWrappedClientLevel() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IClientLevelWrapper clientLevel = mc.getWrappedClientLevel();
|
||||
MinecraftRenderWrapper.INSTANCE.updateLightmap(this.lightPixels, clientLevel);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -45,7 +45,7 @@ import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
#endif
|
||||
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
import net.minecraft.client.gui.screens.OptionsScreen;
|
||||
#else
|
||||
import net.minecraft.client.gui.screens.options.OptionsScreen;
|
||||
@@ -64,7 +64,7 @@ public class MixinOptionsScreen extends Screen
|
||||
/** Texture used for the config opening button */
|
||||
@Unique
|
||||
private static final ResourceLocation ICON_TEXTURE =
|
||||
#if MC_VER < MC_1_21_1
|
||||
#if MC_VER < MC_1_21
|
||||
new ResourceLocation(ModInfo.ID, "textures/gui/button.png");
|
||||
#else
|
||||
ResourceLocation.fromNamespaceAndPath(ModInfo.ID, "textures/gui/button.png");
|
||||
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package com.seibel.distanthorizons.neoforge.mixins.server;
|
||||
|
||||
import com.seibel.distanthorizons.common.commonMixins.MixinChunkMapCommon;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ChunkMap.class)
|
||||
public class MixinChunkMap
|
||||
{
|
||||
|
||||
@Unique
|
||||
private static final String CHUNK_SERIALIZER_WRITE
|
||||
= "Lnet/minecraft/world/level/chunk/storage/ChunkSerializer;write(" +
|
||||
"Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/chunk/ChunkAccess;)" +
|
||||
"Lnet/minecraft/nbt/CompoundTag;";
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
ServerLevel level;
|
||||
|
||||
// firing at INVOKE causes issues with C2ME and is probably unnecessary since we
|
||||
// don't need the chunk(s) before MC has finished saving them
|
||||
@Inject(method = "save", at = @At(value = "RETURN", target = CHUNK_SERIALIZER_WRITE))
|
||||
private void onChunkSave(ChunkAccess chunk, CallbackInfoReturnable<Boolean> ci)
|
||||
{ MixinChunkMapCommon.onChunkSave(this.level, chunk, ci); }
|
||||
|
||||
}
|
||||
-73
@@ -1,73 +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;
|
||||
|
||||
|
||||
@Unique
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,17 +5,11 @@
|
||||
"mixins": [
|
||||
"server.MixinUtilBackgroundThread",
|
||||
"server.MixinChunkGenerator",
|
||||
"server.MixinTFChunkGenerator",
|
||||
"server.MixinChunkMap",
|
||||
"server.MixinServerPlayer"
|
||||
"server.MixinTFChunkGenerator"
|
||||
],
|
||||
"client": [
|
||||
"client.MixinClientPacketListener",
|
||||
"client.MixinDebugScreenOverlay",
|
||||
"client.MixinFogRenderer",
|
||||
"client.MixinGameRenderer",
|
||||
"client.MixinLevelRenderer",
|
||||
"client.MixinLightTexture",
|
||||
"client.MixinOptionsScreen",
|
||||
"client.MixinTextureUtil"
|
||||
],
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user