Skip to content

Commit

Permalink
support more minecraft versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Yancey2023 committed Sep 26, 2024
1 parent d60814b commit 5b58270
Show file tree
Hide file tree
Showing 81 changed files with 1,632 additions and 179 deletions.
96 changes: 96 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
plugins {
// If you're using Kotlin, it needs to be applied before the multi-version plugin
// kotlin("jvm")
// Apply the multi-version plugin, this does all the configuration necessary for the preprocessor to
// work. In particular it also applies `com.replaymod.preprocess`.
// In addition it primarily also provides a `platform` extension which you can use in this build script
// to get the version and mod loader of the current project.
id("gg.essential.multi-version")
// If you do not care too much about the details, you can just apply essential-gradle-toolkits' defaults for
// Minecraft, fabric-loader, forge, mappings, etc. versions.
// You can also overwrite some of these if need be. See the `gg.essential.defaults.loom` README section.
// Otherwise you'll need to configure those as usual for (architectury) loom.
id("gg.essential.defaults")
}

val mcVersion = platform.mcVersion

version = "${project.name}-${rootProject.version}"
base.archivesName.set("openparticle")
java.withSourcesJar()

val fabricApiVersion = when (mcVersion) {
11600, 11601, 11602, 11603, 11604, 11605 -> "0.42.0+1.16"
11700, 11701 -> "0.46.1+1.17"
11800, 11801 -> "0.44.0+1.18"
11802 -> "0.77.0+1.18.2"
11900 -> "0.58.0+1.19"
11901 -> "0.58.5+1.19.1"
11902 -> "0.77.0+1.19.2"
11903 -> "0.76.1+1.19.3"
11904 -> "0.87.2+1.19.4"
12000 -> "0.83.0+1.20"
12001 -> "0.92.2+1.20.1"
12002 -> "0.91.6+1.20.2"
12003 -> "0.91.1+1.20.3"
12004 -> "0.97.1+1.20.4"
12005 -> "0.97.8+1.20.5"
12006 -> "0.100.8+1.20.6"
12100 -> "0.102.0+1.21"
12101 -> "0.105.0+1.21.1"
else -> throw UnsupportedOperationException()
}

dependencies {
// If you are depending on a multi-version library following the same scheme as the Essential libraries (that is
// e.g. `elementa-1.8.9-forge`), you can `toString` `platform` directly to get the respective artifact id.
// modImplementation("gg.essential:elementa-$platform:428")
if (platform.isFabric) {
val fabricApiModules = mutableListOf(
"fabric-api-base",
"fabric-networking-v0",
"fabric-command-api-v1",
"fabric-renderer-registries-v1",
"fabric-lifecycle-events-v1",
"fabric-keybindings-v0",
)
if (mcVersion >= 11604) {
fabricApiModules.remove("fabric-networking-v0")
fabricApiModules.add("fabric-networking-api-v1")
}
if (mcVersion >= 19000) {
fabricApiModules.remove("fabric-command-api-v1")
fabricApiModules.add("fabric-command-api-v2")
}
if (mcVersion >= 11802) {
fabricApiModules.remove("fabric-renderer-registries-v1")
fabricApiModules.add("fabric-rendering-v1")
}

for (module in fabricApiModules) {
val dep = fabricApi.module(module, fabricApiVersion)
modImplementation(dep)
"include"(dep)
}
}
}

loom {
// If you need to use a tweaker on legacy (1.12.2 and below) forge:
// if (platform.isLegacyForge) {
// launchConfigs.named("client") {
// arg("--tweakClass", "gg.essential.loader.stage0.EssentialSetupTweaker")
// // And maybe a core mod?
// // property("fml.coreMods.load", "com.example.asm.CoreMod")
// }
// }
// Mixin on forge? (for legacy forge you will still need to register a tweaker to set up mixin)
// if (platform.isForge) {
// forge {
// mixinConfig("openparticle.mixins.json")
// // And maybe an access transformer?
// // Though try to avoid these, cause they are not automatically translated to Fabric's access widener
// accessTransformer(project.parent.file("src/main/resources/openparticle.cfg"))
// }
// }
}
50 changes: 50 additions & 0 deletions copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
import shutil

modId = 'openparticle'
modVersion = '2.8'
mcVersions = [
"1.16-fabric",
"1.16.1-fabric",
"1.16.2-fabric",
"1.16.3-fabric",
"1.16.4-fabric",
"1.16.5-fabric",
"1.17-fabric",
"1.17.1-fabric",
"1.18-fabric",
"1.18.1-fabric",
"1.18.2-fabric",
"1.19-fabric",
"1.19.1-fabric",
"1.19.2-fabric",
"1.19.3-fabric",
"1.19.4-fabric",
"1.20-fabric",
"1.20.1-fabric",
"1.20.2-fabric",
"1.20.3-fabric",
"1.20.4-fabric",
"1.20.5-fabric",
"1.20.6-fabric",
"1.21-fabric",
"1.21.1-fabric"
]

release_dest = "./build/libs/release"
sources_dest = "./build/libs/sources"

if not os.path.exists(release_dest):
os.makedirs(release_dest)
if not os.path.exists(sources_dest):
os.makedirs(sources_dest)

for mcVersion in mcVersions:
shutil.copyfile(
f"./versions/{mcVersion}/build/libs/{modId}-{mcVersion}-{modVersion}.jar",
f"./build/libs/release/{modId}-{mcVersion}-{modVersion}.jar"
)
shutil.copyfile(
f"./versions/{mcVersion}/build/libs/{modId}-{mcVersion}-{modVersion}-sources.jar",
f"./build/libs/sources/{modId}-{mcVersion}-{modVersion}-sources.jar"
)
19 changes: 6 additions & 13 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx8G
org.gradle.parallel=true
org.gradle.configureondemand=true

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.21.1
yarn_mappings=1.21.1+build.3
loader_version=0.16.5
essential.defaults.loom=0
essential.defaults.loom.fabric-loader=net.fabricmc:fabric-loader:0.16.5

# Fabric API
fabric_version=0.104.0+1.21.1

# Mod Properties
mod_version = 1.21.1-2.7-fabric
maven_group = yancey.openparticle
archives_base_name = OpenParticle
version=2.8
77 changes: 77 additions & 0 deletions root.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
// This marks the current project as the root of a multi-version project.
// Any project using `gg.essential.multi-version` must have a parent with this root plugin applied.
// Advanced users may use multiple (potentially independent) multi-version trees in different sub-projects.
// This is currently equivalent to applying `com.replaymod.preprocess-root`.
id("gg.essential.multi-version.root")
}

group = "yancey.openparticle"
version = project.version

preprocess {
// Here you first need to create a node per version you support and assign it an integer Minecraft version.
// The mappings value is currently meaningless.
val fabric11600 = createNode("1.16-fabric", 11600, "yarn")
val fabric11601 = createNode("1.16.1-fabric", 11601, "yarn")
val fabric11602 = createNode("1.16.2-fabric", 11602, "yarn")
val fabric11603 = createNode("1.16.3-fabric", 11603, "yarn")
val fabric11604 = createNode("1.16.4-fabric", 11604, "yarn")
val fabric11605 = createNode("1.16.5-fabric", 11605, "yarn")
val fabric11700 = createNode("1.17-fabric", 11700, "yarn")
val fabric11701 = createNode("1.17.1-fabric", 11701, "yarn")
val fabric11800 = createNode("1.18-fabric", 11800, "yarn")
val fabric11801 = createNode("1.18.1-fabric", 11801, "yarn")
val fabric11802 = createNode("1.18.2-fabric", 11802, "yarn")
val fabric11900 = createNode("1.19-fabric", 11900, "yarn")
val fabric11901 = createNode("1.19.1-fabric", 11901, "yarn")
val fabric11902 = createNode("1.19.2-fabric", 11902, "yarn")
val fabric11903 = createNode("1.19.3-fabric", 11903, "yarn")
val fabric11904 = createNode("1.19.4-fabric", 11904, "yarn")
val fabric12000 = createNode("1.20-fabric", 12000, "yarn")
val fabric12001 = createNode("1.20.1-fabric", 12001, "yarn")
val fabric12002 = createNode("1.20.2-fabric", 12002, "yarn")
val fabric12003 = createNode("1.20.3-fabric", 12003, "yarn")
val fabric12004 = createNode("1.20.4-fabric", 12004, "yarn")
val fabric12005 = createNode("1.20.5-fabric", 12005, "yarn")
val fabric12006 = createNode("1.20.6-fabric", 12006, "yarn")
val fabric12100 = createNode("1.21-fabric", 12100, "yarn")
val fabric12101 = createNode("1.21.1-fabric", 12101, "yarn")

// And then you need to tell the preprocessor which versions it should directly convert between.
// This should form a directed graph with no cycles (i.e. a tree), which the preprocessor will then traverse to
// produce source code for all versions from the main version.
// Do note that the preprocessor can only convert between two projects when they are either on the same Minecraft
// version (but use different mappings, e.g. 1.16.2 forge to fabric), or when they are using the same intermediary
// mappings (but on different Minecraft versions, e.g. 1.12.2 forge to 1.8.9 forge, or 1.16.2 fabric to 1.18 fabric)
// but not both at the same time, i.e. you cannot go straight from 1.12.2 forge to 1.16.2 fabric, you need to go via
// an intermediary 1.16.2 forge project which has something in common with both.
fabric12101.link(fabric12100)
fabric12100.link(fabric12006)
fabric12006.link(fabric12005)
fabric12005.link(fabric12004)
fabric12004.link(fabric12003)
fabric12003.link(fabric12002)
fabric12002.link(fabric12001)
fabric12001.link(fabric12000)
fabric12000.link(fabric11904)
fabric11904.link(fabric11903)
fabric11903.link(fabric11902)
fabric11902.link(fabric11901)
fabric11901.link(fabric11900)
fabric11900.link(fabric11802)
fabric11802.link(fabric11801, file("versions/mapping-1.18.2-1.18.1.txt"))
fabric11801.link(fabric11800)
fabric11800.link(fabric11701)
fabric11701.link(fabric11700)
fabric11700.link(fabric11605)
fabric11605.link(fabric11604)
fabric11604.link(fabric11603)
fabric11603.link(fabric11602)
fabric11602.link(fabric11601)
fabric11601.link(fabric11600)
// For any link, you can optionally specify a file containing extra mappings which the preprocessor cannot infer by
// itself, e.g. forge intermediary names do not contain class names, so you may need to supply mappings for those
// manually.
// forge11202.link(forge10809, file("versions/1.12.2-1.8.9.txt"))
}
9 changes: 0 additions & 9 deletions settings.gradle

This file was deleted.

58 changes: 58 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
maven("https://maven.fabricmc.net")
maven("https://maven.architectury.dev/")
maven("https://maven.minecraftforge.net")
maven("https://repo.essential.gg/repository/maven-public")
}
// We also recommend specifying your desired version here if you're using more than one of the plugins,
// so you do not have to change the version in multilpe places when updating.
plugins {
val egtVersion = "0.6.2" // should be whatever is displayed in above badge
id("gg.essential.multi-version.root") version egtVersion
id("gg.essential.multi-version.api-validation") version egtVersion
}
}

listOf(
"1.16-fabric",
"1.16.1-fabric",
"1.16.2-fabric",
"1.16.3-fabric",
"1.16.4-fabric",
"1.16.5-fabric",
"1.17-fabric",
"1.17.1-fabric",
"1.18-fabric",
"1.18.1-fabric",
"1.18.2-fabric",
"1.19-fabric",
"1.19.1-fabric",
"1.19.2-fabric",
"1.19.3-fabric",
"1.19.4-fabric",
"1.20-fabric",
"1.20.1-fabric",
"1.20.2-fabric",
"1.20.3-fabric",
"1.20.4-fabric",
"1.20.5-fabric",
"1.20.6-fabric",
"1.21-fabric",
"1.21.1-fabric",
).forEach { version ->
include(":$version")
project(":$version").apply {
// This is where the `build` folder and per-version overwrites will reside
projectDir = file("versions/$version")
// All sub-projects get configured by the same `build.gradle.kts.kts` file, the string is relative to projectDir
// You could use separate build files for each project, but usually that would just be duplicating lots of code
buildFileName = "../../build.gradle.kts"
}
}

// We use the `build.gradle.kts` file for all the sub-projects (cause that's where most the interesting stuff lives),
// so we need to use a different build file for the original root project.
rootProject.buildFileName = "root.gradle.kts"
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public int getVBOSize() {
*/
private native static void render(long pointer, long bufferPointer, boolean isSingleThread, float tickDelta, float cameraX, float cameraY, float cameraZ, float rx, float ry, float rz, float rw);

@SuppressWarnings({"unused", "DuplicatedCode"})
public void render(Buffer directBuffer, boolean isSingleThread, float tickDelta, float cameraX, float cameraY, float cameraZ, float rx, float ry, float rz, float rw) {
if (!directBuffer.isDirect()) {
throw new RuntimeException("buffer is not direct");
Expand Down Expand Up @@ -177,6 +178,7 @@ public void close() {
*/
private native static void render(long pointer, Buffer directBuffer, boolean isSingleThread, float tickDelta, float cameraX, float cameraY, float cameraZ, float rx, float ry, float rz, float rw);

@SuppressWarnings({"unused", "DuplicatedCode"})
public void render(long bufferPointer, boolean isSingleThread, float tickDelta, float cameraX, float cameraY, float cameraZ, float rx, float ry, float rz, float rw) {
if (tickDelta < 0 || tickDelta > 1) {
throw new RuntimeException("Tick delta out of range: " + tickDelta);
Expand Down
41 changes: 27 additions & 14 deletions src/main/java/yancey/openparticle/core/OpenParticle.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
package yancey.openparticle.core;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import yancey.openparticle.core.command.CommandPar;
import yancey.openparticle.core.core.OpenParticleServerCore;
import yancey.openparticle.core.keys.KeyboardManager;
import yancey.openparticle.core.network.*;

//#if MC>=12005
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
//#endif

//#if MC>=19000
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
//#else
//$$ import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
//#endif

public class OpenParticle implements ModInitializer {

public static final String MOD_ID = "openparticle";

@Override
public void onInitialize() {
PayloadTypeRegistry.playC2S().register(KeyboardPayloadC2S.ID, KeyboardPayloadC2S.CODEC);
PayloadTypeRegistry.playC2S().register(RunPayloadC2S.ID, RunPayloadC2S.CODEC);
PayloadTypeRegistry.playS2C().register(RunTickPayloadS2C.ID, RunTickPayloadS2C.CODEC);
PayloadTypeRegistry.playS2C().register(LoadAndRunPayloadS2C.ID, LoadAndRunPayloadS2C.CODEC);
PayloadTypeRegistry.playS2C().register(LoadPayloadS2C.ID, LoadPayloadS2C.CODEC);
PayloadTypeRegistry.playS2C().register(RunPayloadS2C.ID, RunPayloadS2C.CODEC);
ServerPlayNetworking.registerGlobalReceiver(KeyboardPayloadC2S.ID, (payload, context) ->
context.player().server.execute(() -> KeyboardManager.runInServe(payload.idList(), context.player())));
ServerPlayNetworking.registerGlobalReceiver(RunPayloadC2S.ID, (payload, context) ->
OpenParticleServerCore.run(context.player().server, payload.path(), payload.tickEnd(), payload.isSingleThread()));
//#if MC>=12005
PayloadTypeRegistry.playC2S().register(KeyboardPayloadC2S.ID.getId(), KeyboardPayloadC2S.ID.getCodec());
PayloadTypeRegistry.playC2S().register(RunPayloadC2S.ID.getId(), RunPayloadC2S.ID.getCodec());
PayloadTypeRegistry.playS2C().register(RunTickPayloadS2C.ID.getId(), RunTickPayloadS2C.ID.getCodec());
PayloadTypeRegistry.playS2C().register(LoadAndRunPayloadS2C.ID.getId(), LoadAndRunPayloadS2C.ID.getCodec());
PayloadTypeRegistry.playS2C().register(LoadPayloadS2C.ID.getId(), LoadPayloadS2C.ID.getCodec());
PayloadTypeRegistry.playS2C().register(RunPayloadS2C.ID.getId(), RunPayloadS2C.ID.getCodec());
//#endif
KeyboardPayloadC2S.ID.registerServerGlobalReceiver((payload, server, player) ->
player.server.execute(() -> KeyboardManager.runInServe(payload.idList, player)));
RunPayloadC2S.ID.registerServerGlobalReceiver((payload, server, player) ->
OpenParticleServerCore.run(player.server, payload.path, payload.tickEnd, payload.isSingleThread));
KeyboardManager.init(false);
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> CommandPar.init(dispatcher));
//#if MC>=19000
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> CommandPar.register(dispatcher));
//#else
//$$ CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> CommandPar.register(dispatcher));
//#endif
}
}
Loading

0 comments on commit 5b58270

Please sign in to comment.