From e40c39a6de947f24362c1593f31e2dced0ba450d Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Sat, 20 Jul 2024 14:52:47 +0200 Subject: [PATCH 1/4] initial common ID extender api impl --- README.MD | 46 +++++++++++++++++++ build.gradle.kts | 5 ++ .../constants/ExtendedConstants.java | 3 ++ .../constants/VanillaConstants.java | 3 ++ src/main/java/idextender/IDExtender.java | 14 ++++++ src/main/java/idextender/Metadata.java | 16 +++++++ src/main/java/idextender/package-info.java | 4 ++ 7 files changed, 91 insertions(+) create mode 100644 src/main/java/idextender/IDExtender.java create mode 100644 src/main/java/idextender/Metadata.java create mode 100644 src/main/java/idextender/package-info.java diff --git a/README.MD b/README.MD index e2e8844..d932fd9 100644 --- a/README.MD +++ b/README.MD @@ -98,3 +98,49 @@ Mods not listed here may or may not work. user to this GitHub repo. If you find any crashes or incompatibilities, don't hesitate to open an issue. + +## Depending On Metadata Increase In Another Mod + +**NOTE:** This API is available as of version of EndlessIDs. + +EndlessIDs implements the common ID Extender API added in NotEnoughIDs Unofficial. See: +https://github.com/GTNewHorizons/NotEnoughIds/pull/17 + +The description below is an excerpt of NEID-U's readme concerning this API: + +In order to use the metadata, you should not create a hard dependency on the `endlessids` Mod ID, but rather on the `idextender` Mod ID. +EndlessIDs bundles this "dummy" mod alongside itself. + +Here is an example of how to use it, you could put this code in your Mod's pre-init for example: + +```java +import idextender; + +int maxMeta = 15; + +if (Loader.isModLoaded("idextender")) { + maxMeta = (Integer) Class.forName("idextender.Metadata").getDeclaredMethod("maximumMetadata").invoke(null); +} +``` + +You can also query for the number of bits the metadata value is extended to, rather than the maximum value: + +```java +import idextender; + +int metadataBits = 4; + +if (Loader.isModLoaded("idextender")){ + metadataBits = (Integer) Class.forName("idextender.Metadata").getDeclaredMethod("metadataBits").invoke(null); +} +``` + +If for some reason, you need to know what parent mod is providing the `idextender` mod, you can do the following, which will give you +back the Mod ID of the actual mod that has provided `idextender`. For example, `endlessids`: + +```java +// This will give back the value "endlessids" which is EndlessIDs' Mod ID +String parentIDExtender = (String) Class.forName("idextender.IDExtender").getDeclaredMethod("parentModId").invoke(null); +``` + +For more information, see the NotEnoughIDs readme. \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 5c6b131..70ccaee 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,6 +11,11 @@ minecraft_fp { rootPkg = "$group.endlessids" } + api { + packages = listOf("idextender") + ignoreRootPkg = true + } + mixin { pkg = "mixin.mixins" pluginClass = "mixin.plugin.MixinPlugin" diff --git a/src/main/java/com/falsepattern/endlessids/constants/ExtendedConstants.java b/src/main/java/com/falsepattern/endlessids/constants/ExtendedConstants.java index 0cfd40f..d580c1f 100644 --- a/src/main/java/com/falsepattern/endlessids/constants/ExtendedConstants.java +++ b/src/main/java/com/falsepattern/endlessids/constants/ExtendedConstants.java @@ -58,6 +58,9 @@ public class ExtendedConstants { public static final int itemIDCount = 1 << (bitsPerID - countCorrectionItemBits); public static final int maxItemID = itemIDCount - 1; + public static final int metadataCount = (1 << bitsPerMetadata); + public static final int maxMetadata = metadataCount - 1; + public static final int bitsPerBlock = 8 + bitsPerID + bitsPerMetadata; public static final int nibblesPerBlock = bitsPerBlock / 4; public static final int nibblesPerSubChunk = nibblesPerBlock * 16 * 16 * 16; diff --git a/src/main/java/com/falsepattern/endlessids/constants/VanillaConstants.java b/src/main/java/com/falsepattern/endlessids/constants/VanillaConstants.java index d83c170..b8c0ac2 100644 --- a/src/main/java/com/falsepattern/endlessids/constants/VanillaConstants.java +++ b/src/main/java/com/falsepattern/endlessids/constants/VanillaConstants.java @@ -48,6 +48,9 @@ public class VanillaConstants { public static final int itemIDCount = 32000; public static final int maxItemID = itemIDCount - 1; + public static final int metadataCount = (1 << bitsPerMetadata); + public static final int maxMetadata = metadataCount - 1; + public static final int bitsPerBlock = 8 + bitsPerID + bitsPerMetadata; public static final int nibblesPerBlock = bitsPerBlock / 4; public static final int nibblesPerSubChunk = nibblesPerBlock * 16 * 16 * 16; diff --git a/src/main/java/idextender/IDExtender.java b/src/main/java/idextender/IDExtender.java new file mode 100644 index 0000000..a66acae --- /dev/null +++ b/src/main/java/idextender/IDExtender.java @@ -0,0 +1,14 @@ +package idextender; + +import com.falsepattern.endlessids.Tags; + +import cpw.mods.fml.common.Mod; + +@Mod(modid = "idextender", name = "ID Extender", version = "1.0.0") +public class IDExtender { + + public static String parentModId() { + return Tags.MODID; + } + +} diff --git a/src/main/java/idextender/Metadata.java b/src/main/java/idextender/Metadata.java new file mode 100644 index 0000000..ffa6355 --- /dev/null +++ b/src/main/java/idextender/Metadata.java @@ -0,0 +1,16 @@ +package idextender; + +import com.falsepattern.endlessids.config.GeneralConfig; +import com.falsepattern.endlessids.constants.ExtendedConstants; +import com.falsepattern.endlessids.constants.VanillaConstants; + +public class Metadata { + public static int maximumMetadata() { + return GeneralConfig.extendBlockItem ? ExtendedConstants.maxMetadata : VanillaConstants.maxMetadata; + } + + public static int metadataBits() { + return GeneralConfig.extendBlockItem ? ExtendedConstants.bitsPerMetadata : VanillaConstants.bitsPerMetadata; + } + +} \ No newline at end of file diff --git a/src/main/java/idextender/package-info.java b/src/main/java/idextender/package-info.java new file mode 100644 index 0000000..079e71f --- /dev/null +++ b/src/main/java/idextender/package-info.java @@ -0,0 +1,4 @@ +/** + * Interop with NEID Unofficial, to let mods avoid hard-depending on either NEIDu or EndlessIDs + */ +package idextender; \ No newline at end of file From 97175b47b972fed5e229ab19b0625640a8b90d35 Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Sat, 21 Sep 2024 12:40:22 +0200 Subject: [PATCH 2/4] IDExtender make child of endlessids --- src/main/resources/mcmod.info | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 0e0db8a..fdecdf7 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -14,5 +14,11 @@ "logoFile": "", "screenshots": [], "dependencies": [] + }, + { + "modid": "idextender", + "name": "ID Extender", + "version": "1.0.0", + "parent": "${modId}" } ] From aa1f8e76fa1cf0df09425a04abec56a6484cbe22 Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Sat, 21 Sep 2024 12:46:44 +0200 Subject: [PATCH 3/4] update readme with notice --- README.MD | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.MD b/README.MD index d932fd9..7b87d68 100644 --- a/README.MD +++ b/README.MD @@ -101,9 +101,9 @@ If you find any crashes or incompatibilities, don't hesitate to open an issue. ## Depending On Metadata Increase In Another Mod -**NOTE:** This API is available as of version of EndlessIDs. +**NOTE:** This API is available as of version TODO of EndlessIDs. -EndlessIDs implements the common ID Extender API added in NotEnoughIDs Unofficial. See: +EndlessIDs implements the common ID Extender API introduced in NotEnoughIDs Unofficial. See: https://github.com/GTNewHorizons/NotEnoughIds/pull/17 The description below is an excerpt of NEID-U's readme concerning this API: @@ -135,6 +135,10 @@ if (Loader.isModLoaded("idextender")){ } ``` +Note that these values CAN be identical to the vanilla values if the ID Extension mod implementing it has a config to +toggle itself, existence of the IDExtender class does not guarantee a fixed increase, and you should check that the +returned value is large enough for your needs. + If for some reason, you need to know what parent mod is providing the `idextender` mod, you can do the following, which will give you back the Mod ID of the actual mod that has provided `idextender`. For example, `endlessids`: From 213d5b56c7d8926609271deb7787d5c9b18bf86c Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Sat, 21 Sep 2024 12:54:14 +0200 Subject: [PATCH 4/4] DataWatcher idextender API --- README.MD | 5 ++++- src/main/java/idextender/DataWatcher.java | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/main/java/idextender/DataWatcher.java diff --git a/README.MD b/README.MD index 7b87d68..44bff78 100644 --- a/README.MD +++ b/README.MD @@ -25,7 +25,7 @@ If you notice any problems when opening NEID worlds with EndlessIDs, please open | Entity IDs | 256 | 256 | 256 | 32,768 | | Potion IDs | 32 | 32 | 32 | 65,536 | | Enchantment IDs | 256 | 256 | 256 | 32,768 | -| DataWatcher IDs | 32 | 127 (Broken) | 127 (Broken) | 65,536 | +| DataWatcher IDs | 32 | 127 (Broken) | 127 | 65,536 | | Dimension IDs | Theoretically unlimited, 4,294,967,295 in practice | Same | Same | Same | ## Mod compat @@ -135,6 +135,9 @@ if (Loader.isModLoaded("idextender")){ } ``` +The `idextender.DataWatcher` class also exposes the extended DataWatcher count (used for entity data syncing over network) +in a similar fashion. + Note that these values CAN be identical to the vanilla values if the ID Extension mod implementing it has a config to toggle itself, existence of the IDExtender class does not guarantee a fixed increase, and you should check that the returned value is large enough for your needs. diff --git a/src/main/java/idextender/DataWatcher.java b/src/main/java/idextender/DataWatcher.java new file mode 100644 index 0000000..973393d --- /dev/null +++ b/src/main/java/idextender/DataWatcher.java @@ -0,0 +1,16 @@ +package idextender; + +import com.falsepattern.endlessids.config.GeneralConfig; +import com.falsepattern.endlessids.constants.ExtendedConstants; +import com.falsepattern.endlessids.constants.VanillaConstants; + +public class DataWatcher { + public static int maxWatchableID() { + return GeneralConfig.extendDataWatcher ? ExtendedConstants.maxWatchableID : VanillaConstants.maxWatchableID; + } + + public static int watchableBits() { + return GeneralConfig.extendDataWatcher ? ExtendedConstants.watchableBits : VanillaConstants.watchableBits; + } + +} \ No newline at end of file