From 4889287e69e0befdfdd8cd3a1e6da942748279d2 Mon Sep 17 00:00:00 2001 From: s809 <11816467-s809@users.noreply.gitlab.com> Date: Fri, 29 Dec 2023 20:31:07 +0500 Subject: [PATCH] Start porting to previous versions --- .gitlab-ci.yml | 2 +- .../wrappers/misc/ServerPlayerWrapper.java | 3 +- fabric/build.gradle | 7 ++-- .../fabric/FabricClientProxy.java | 12 ++++--- .../fabric/FabricDedicatedServerMain.java | 33 ++++++++++++++++--- .../fabric/FabricServerProxy.java | 6 ---- 6 files changed, 44 insertions(+), 19 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f8864693a..0653bb904 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ build: stage: build parallel: matrix: - - MC_VER: ["1.20.1", "1.20.2", "1.20.4"] + - MC_VER: ["1.17.1", "1.18.2", "1.19.2", "1.19.4", "1.20.1", "1.20.2", "1.20.4"] # - 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"] script: # this both runs the unit tests and assembles the code diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java index d14451139..917cbec54 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/misc/ServerPlayerWrapper.java @@ -6,6 +6,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapp import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper; import com.seibel.distanthorizons.coreapi.util.math.Vec3d; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.phys.Vec3; import java.util.UUID; import java.util.concurrent.ConcurrentMap; @@ -42,7 +43,7 @@ public class ServerPlayerWrapper implements IServerPlayerWrapper } public Vec3d getPosition() { - var position = serverPlayer.position(); + Vec3 position = serverPlayer.position(); return new Vec3d(position.x, position.y, position.z); } diff --git a/fabric/build.gradle b/fabric/build.gradle index 62e2f9eef..429b47417 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -64,8 +64,11 @@ dependencies { 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)) - addModJar(fabricApi.module("fabric-command-api-v2", 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)) + // Mod Menu modImplementation("com.terraformersmc:modmenu:${rootProject.modmenu_version}") diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java index 019b034c0..638d326f8 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricClientProxy.java @@ -19,12 +19,13 @@ package com.seibel.distanthorizons.fabric; -import com.mojang.blaze3d.platform.InputConstants; import com.seibel.distanthorizons.common.rendering.SeamlessOverdraw; import com.seibel.distanthorizons.common.wrappers.McObjectConverter; -import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper; import com.seibel.distanthorizons.core.api.internal.ClientApi; +import com.mojang.blaze3d.platform.InputConstants; +import com.seibel.distanthorizons.common.wrappers.chunk.ChunkWrapper; + import com.seibel.distanthorizons.core.api.internal.SharedApi; import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector; @@ -47,6 +48,10 @@ import net.fabricmc.fabric.api.event.player.UseBlockCallback; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.TitleScreen; + +import java.nio.FloatBuffer; +import java.util.HashSet; + import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.network.FriendlyByteBuf; @@ -56,8 +61,7 @@ import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.phys.HitResult; import org.apache.logging.log4j.Logger; import org.lwjgl.glfw.GLFW; - -import java.util.HashSet; +import org.lwjgl.opengl.GL15; /** * This handles all events sent to the client, diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricDedicatedServerMain.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricDedicatedServerMain.java index 36b1afc36..8026a3421 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricDedicatedServerMain.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricDedicatedServerMain.java @@ -20,11 +20,16 @@ import com.seibel.distanthorizons.core.util.objects.Pair; import net.fabricmc.api.DedicatedServerModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +#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 net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.dedicated.DedicatedServer; import org.apache.logging.log4j.LogManager; @@ -65,7 +70,12 @@ public class FabricDedicatedServerMain implements DedicatedServerModInitializer server_proxy = new FabricServerProxy(true); server_proxy.registerEvents(); + + #if MC_VER > MC_1_19_2 CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { + #else // < 1.19.2 + CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> { + #endif this.commandDispatcher = dispatcher; }); @@ -97,28 +107,41 @@ public class FabricDedicatedServerMain implements DedicatedServerModInitializer for (AbstractConfigType type : ConfigBase.INSTANCE.entries) { - if (!(type instanceof ConfigEntry configEntry)) continue; + if (!(type instanceof ConfigEntry)) continue; + ConfigEntry configEntry = (ConfigEntry) type; if (configEntry.getServersideShortName() == null) continue; Function< Function, Object>, Command > makeConfigUpdater = getter -> c -> { - var value = getter.apply(c); + Object value = getter.apply(c); + #if MC_VER >= MC_1_20_1 c.getSource().sendSuccess(() -> Component.literal("Changed the value of "+configEntry.getServersideShortName()+" to "+value), true); + #elif MC_VER >= MC_1_19_2 + c.getSource().sendSuccess(Component.literal("Changed the value of "+configEntry.getServersideShortName()+" to "+value), true); + #else // < 1.19.2 + c.getSource().sendSuccess(new TranslatableComponent("Changed the value of "+configEntry.getServersideShortName()+" to "+value), true); + #endif configEntry.set(value); return 1; }; - var subcommand = literal(configEntry.getServersideShortName()) + LiteralArgumentBuilder subcommand = literal(configEntry.getServersideShortName()) .executes(c -> { + #if MC_VER >= MC_1_20_1 c.getSource().sendSuccess(() -> Component.literal("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true); + #elif MC_VER >= MC_1_19_2 + c.getSource().sendSuccess(Component.literal("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true); + #else // < 1.19.2 + c.getSource().sendSuccess(new TranslatableComponent("Current value of "+configEntry.getServersideShortName()+" is "+configEntry.get()), true); + #endif return 1; }); if (Enum.class.isAssignableFrom(configEntry.getType())) { - for (var choice : configEntry.getType().getEnumConstants()) + for (Object choice : configEntry.getType().getEnumConstants()) { subcommand.then( literal(choice.toString()) @@ -130,7 +153,7 @@ public class FabricDedicatedServerMain implements DedicatedServerModInitializer { boolean setterAdded = false; - for (var pair : new HashMap< + for (java.util.Map.Entry, Pair>, BiFunction, String, ?>>> pair : new HashMap< Class, Pair< Supplier>, diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java index 751672d6e..79ba7c760 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/FabricServerProxy.java @@ -9,7 +9,6 @@ import com.seibel.distanthorizons.core.api.internal.ServerApi; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; 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; @@ -19,17 +18,12 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.TitleScreen; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import org.apache.logging.log4j.Logger; import java.util.function.Supplier; -import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; -import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; -import static net.minecraft.commands.Commands.*; - /** * This handles all events sent to the server, * and is the starting point for most of the mod.