From 56dca865548a418d53594f4d7c06e62eba0234c5 Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Sun, 31 Dec 2023 16:01:52 -0600 Subject: [PATCH] Update to 1.20.4 --- .gitignore | 2 + build.gradle | 50 ++++++++---- common/build.gradle | 9 --- .../trenzalore/TestItems.java | 26 ++++++ .../trenzalore/api/config/ConfigManger.java | 10 +-- .../platform/services/IPlatformHelper.java | 8 +- .../trenzalore/api/registry/Regeneration.java | 12 +-- .../api/registry/RegistryFactory.java | 9 --- .../trenzalore/lib/CustomCodecs.java | 31 ------- .../main/resources/trenzalore.accesswidener | 2 +- fabric/build.gradle | 6 -- .../platform/FabricPlatformHelper.java | 2 +- forge/build.gradle | 17 ---- .../trenzalore/TrenzaloreForge.java | 2 - .../events/ReplaceItemModifier.java | 4 +- .../platform/ForgePlatformHelper.java | 2 +- .../resources/META-INF/accesstransformer.cfg | 2 +- gradle.properties | 13 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- neo/build.gradle | 8 ++ .../trenzalore/TrenzaloreForge.java | 22 +++++ .../trenzalore/TrenzaloreNeoRegistry.java | 29 +++++++ .../trenzalore/events/AddItemModifier.java | 40 +++++++++ .../events/ReplaceItemModifier.java | 48 +++++++++++ .../platform/NeoPlatformHelper.java | 81 +++++++++++++++++++ .../resources/META-INF/accesstransformer.cfg | 14 ++++ neo/src/main/resources/META-INF/mods.toml | 23 ++++++ ...lore.api.platform.services.IPlatformHelper | 1 + ...trenzalore.api.platform.services.IRegistry | 2 + settings.gradle | 16 +++- 30 files changed, 363 insertions(+), 130 deletions(-) create mode 100644 common/src/main/java/com/unrealdinnerbone/trenzalore/TestItems.java delete mode 100644 common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryFactory.java delete mode 100644 common/src/main/java/com/unrealdinnerbone/trenzalore/lib/CustomCodecs.java create mode 100644 neo/build.gradle create mode 100644 neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreForge.java create mode 100644 neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreNeoRegistry.java create mode 100644 neo/src/main/java/com/unrealdinnerbone/trenzalore/events/AddItemModifier.java create mode 100644 neo/src/main/java/com/unrealdinnerbone/trenzalore/events/ReplaceItemModifier.java create mode 100644 neo/src/main/java/com/unrealdinnerbone/trenzalore/platform/NeoPlatformHelper.java create mode 100644 neo/src/main/resources/META-INF/accesstransformer.cfg create mode 100644 neo/src/main/resources/META-INF/mods.toml create mode 100644 neo/src/main/resources/META-INF/services/com.unrealdinnerbone.trenzalore.api.platform.services.IPlatformHelper create mode 100644 neo/src/main/resources/META-INF/services/com.unrealdinnerbone.trenzalore.api.platform.services.IRegistry diff --git a/.gitignore b/.gitignore index a8f53a9..89ce073 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ eclipse run Fabric/run_client/ + +neo/runs/ diff --git a/build.gradle b/build.gradle index 6c31c1a..81c6f06 100644 --- a/build.gradle +++ b/build.gradle @@ -1,20 +1,18 @@ -import dev.nanite.mlp.tasks.SingleOutputJar - plugins { - id("dev.nanite.mlp") version("0.0.3") - id("java") - id "me.modmuss50.mod-publish-plugin" version "0.3.0" - - id("fabric-loom") version("1.3.9") apply(false) - id("net.minecraftforge.gradle") version("6.0.+") apply(false) + id("dev.nanite.mlp") version("0.1.1-SNAPSHOT") + id("java-library") + id("maven-publish") + id("me.modmuss50.mod-publish-plugin") version "0.3.0" } + java.toolchain.languageVersion = JavaLanguageVersion.of(17) multiLoader.root() { minecraftVersion.set(project.property("minecraft_version")) modID.set(project.property("mod_id")) splitSources.set(true) + convertAccessWidener.set(true) accessWidenerFile.set(project(":common").file("src/main/resources/${mod_id}.accesswidener")) } @@ -23,17 +21,20 @@ allprojects { version = "${mod_version}+mc${minecraft_version}${isSnapshot ? '-SNAPSHOT' : ''}" setArchivesBaseName("${mod_name}-${project.name}".toLowerCase()) group = "com.unrealdinnerbone" -} +} + subprojects { - apply plugin: 'dev.nanite.mlp' + + + apply plugin: 'java-library' apply plugin: 'maven-publish' + apply plugin: 'dev.nanite.mlp' sourceSets.main.resources.srcDir project.file('src/generated/resources') - base { archivesName = "${project.property("mod_name")}-${project.name}".toLowerCase() } @@ -84,24 +85,33 @@ publishMods { def fabricOptions = publishOptions { file = project.provider { project(":fabric").tasks.remapJar }.flatMap { it.archiveFile } - displayName = "${project.name} Fabric ${mod_version}+mc${minecraft_version}" + displayName = "[FABRIC][${minecraft_version}] ${project.name} ${mod_version}" modLoaders.add("fabric") } def forgeOptions = publishOptions { - file = project.provider { project(":forge").tasks.jarJar }.flatMap { it.archiveFile } - displayName = "${project.name} Forge ${mod_version}+mc${minecraft_version}" + file = project.provider { project(":forge").tasks.remapJar }.flatMap { it.archiveFile } + displayName = "[FORGE][${minecraft_version}] ${project.name} ${mod_version}" modLoaders.add("forge") } + def neoForge = publishOptions { + file = project.provider { project(":neoforge").tasks.remapJar }.flatMap { it.archiveFile } + displayName = "[NEOFORGE][${minecraft_version}] ${project.name} ${mod_version}" + modLoaders.add("neoforge") + } + def curseForgeOptions = curseforgeOptions { accessToken = providers.environmentVariable("CURSE_TOKEN") - projectId = project.property("curse_id") + projectId = "${curseforge_id}" minecraftVersions.add("${minecraft_version}") } curseforge("curseforgeFabric") { from(curseForgeOptions, fabricOptions) + requires { + slug = "architectury-api" + } requires { slug = "fabric-api" } @@ -109,6 +119,16 @@ publishMods { curseforge("curseforgeForge") { from(curseForgeOptions, forgeOptions) + requires { + slug = "architectury-api" + } + } + + curseforge("curseforgeNeoForge") { + from(curseForgeOptions, neoForge) + requires { + slug = "architectury-api" + } } } diff --git a/common/build.gradle b/common/build.gradle index 98446dd..6ccbf78 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -3,12 +3,3 @@ multiLoader.common() publishing.publications.mavenJava.from components.java -dependencies { - api ("com.unrealdinnerbone:UnRealConfig-gson:${unreal_config_version}") { - exclude group: 'com.google.code.gson', module: 'gson' - exclude group: 'org.jetbrains', module: 'annotations' - exclude group: 'org.slf4j', module: 'slf4j-api' - - } -} - diff --git a/common/src/main/java/com/unrealdinnerbone/trenzalore/TestItems.java b/common/src/main/java/com/unrealdinnerbone/trenzalore/TestItems.java new file mode 100644 index 0000000..17b2aa0 --- /dev/null +++ b/common/src/main/java/com/unrealdinnerbone/trenzalore/TestItems.java @@ -0,0 +1,26 @@ +package com.unrealdinnerbone.trenzalore; + +import com.unrealdinnerbone.trenzalore.api.platform.services.IRegistry; +import com.unrealdinnerbone.trenzalore.api.registry.RegistryEntry; +import com.unrealdinnerbone.trenzalore.api.registry.RegistryObjects; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.item.Item; + +import java.util.List; + +public class TestItems implements IRegistry { + + private static final RegistryObjects ITEMS = RegistryObjects.of(Registries.ITEM); + + public static final RegistryEntry TEST_ITEM = ITEMS.register("test_item", () -> new Item(new Item.Properties())); + @Override + public List> getRegistryObjects() { + return List.of(ITEMS); + } + + @Override + public String getModID() { + return Trenzalore.MOD_ID; + } +} diff --git a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/config/ConfigManger.java b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/config/ConfigManger.java index ff4b2c8..a26b5ae 100644 --- a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/config/ConfigManger.java +++ b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/config/ConfigManger.java @@ -3,8 +3,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mojang.logging.LogUtils; -import com.unrealdinnerbone.config.ConfigManager; -import com.unrealdinnerbone.config.gson.GsonProvider; import com.unrealdinnerbone.trenzalore.api.platform.Services; import org.jetbrains.annotations.ApiStatus; import org.slf4j.Logger; @@ -21,7 +19,7 @@ public class ConfigManger { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "4.0.0") + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") public static T getOrCreateConfig(String name, Class tClass, Supplier defaultValue) { Path configPath = Services.PLATFORM.getConfigPath(); Path config = configPath.resolve(name + ".json"); @@ -42,10 +40,4 @@ public static T getOrCreateConfig(String name, Class tClass, Supplier } } - public static ConfigManager createConfigManager(String modid) { - Path configPath = Services.PLATFORM.getConfigPath(); - Path config = configPath.resolve(modid + ".json"); - return new ConfigManager(new GsonProvider(config, GSON)); - } - } diff --git a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/platform/services/IPlatformHelper.java b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/platform/services/IPlatformHelper.java index 16961f6..e114c14 100644 --- a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/platform/services/IPlatformHelper.java +++ b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/platform/services/IPlatformHelper.java @@ -6,7 +6,6 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; @@ -30,14 +29,9 @@ public interface IPlatformHelper { boolean isModLoaded(String modId); - @Nullable - default Entity teleport(T entity, ServerLevel level, PortalInfo portalInfo) { - return teleportInternal(entity, level, portalInfo); - } - @Nullable @ApiStatus.Internal - Entity teleportInternal(T entity, ServerLevel level, PortalInfo portalInfo); + Entity teleport(T entity, ServerLevel level, PortalInfo portalInfo); @ApiStatus.Internal void addItemToCreativeTab(ResourceKey tabResourceKey, List> item); @ApiStatus.Internal diff --git a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/Regeneration.java b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/Regeneration.java index 20284f0..f02f01d 100644 --- a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/Regeneration.java +++ b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/Regeneration.java @@ -6,6 +6,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; @@ -24,16 +25,9 @@ public static RegistryObjects create(ResourceKey> registry) { return RegistryObjects.of(registry); } - public static > T registerCriterion(T criterion) { - return CriteriaTriggers.register(criterion); + public static > T registerCriterion(ResourceLocation name, T criterion) { + return CriteriaTriggers.register(name.toString(), criterion); } - - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "4.0.0") - public static void registerCreativeTabItems(ResourceKey tabResourceKey, List> item) { - addItemsToCreateTab(tabResourceKey, item); - } - public static void addItemToCreateTab(ResourceKey tabResourceKey, Supplier item) { Services.PLATFORM.addItemToCreativeTab(tabResourceKey, List.of(item)); } diff --git a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryFactory.java b/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryFactory.java deleted file mode 100644 index b409d9d..0000000 --- a/common/src/main/java/com/unrealdinnerbone/trenzalore/api/registry/RegistryFactory.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.unrealdinnerbone.trenzalore.api.registry; - -import org.jetbrains.annotations.ApiStatus; - -@Deprecated -@ApiStatus.ScheduledForRemoval(inVersion = "4.0.0") -public class RegistryFactory extends Regeneration { - -} diff --git a/common/src/main/java/com/unrealdinnerbone/trenzalore/lib/CustomCodecs.java b/common/src/main/java/com/unrealdinnerbone/trenzalore/lib/CustomCodecs.java deleted file mode 100644 index 110aefd..0000000 --- a/common/src/main/java/com/unrealdinnerbone/trenzalore/lib/CustomCodecs.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.unrealdinnerbone.trenzalore.lib; - -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.mojang.serialization.Codec; -import com.mojang.serialization.DataResult; -import com.mojang.serialization.DynamicOps; -import com.mojang.serialization.JsonOps; -import com.mojang.serialization.codecs.PrimitiveCodec; -import net.minecraft.world.item.crafting.Ingredient; - -public class CustomCodecs { - - public static final Codec INGREDIENT = new PrimitiveCodec<>() { - - @Override - public DataResult read(DynamicOps ops, T input) { - try { - JsonElement jsonElement = ops.convertTo(JsonOps.INSTANCE, input); - return DataResult.success(Ingredient.fromJson(jsonElement)); - } catch(JsonParseException e) { - return DataResult.error(e::getMessage); - } - } - - @Override - public T write(DynamicOps ops, Ingredient value) { - return JsonOps.INSTANCE.convertTo(ops, value.toJson()); - } - }; -} diff --git a/common/src/main/resources/trenzalore.accesswidener b/common/src/main/resources/trenzalore.accesswidener index 3570b28..75cdca1 100644 --- a/common/src/main/resources/trenzalore.accesswidener +++ b/common/src/main/resources/trenzalore.accesswidener @@ -1,5 +1,5 @@ accessWidener v1 named -accessible method net/minecraft/advancements/CriteriaTriggers register (Lnet/minecraft/advancements/CriterionTrigger;)Lnet/minecraft/advancements/CriterionTrigger; +accessible method net/minecraft/advancements/CriteriaTriggers register (Ljava/lang/String;Lnet/minecraft/advancements/CriterionTrigger;)Lnet/minecraft/advancements/CriterionTrigger; accessible field net/minecraft/world/item/CreativeModeTabs BUILDING_BLOCKS Lnet/minecraft/resources/ResourceKey; accessible field net/minecraft/world/item/CreativeModeTabs COLORED_BLOCKS Lnet/minecraft/resources/ResourceKey; accessible field net/minecraft/world/item/CreativeModeTabs NATURAL_BLOCKS Lnet/minecraft/resources/ResourceKey; diff --git a/fabric/build.gradle b/fabric/build.gradle index 3c68ce9..3e53493 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -5,12 +5,6 @@ multiLoader.fabric() { publishing.publications.mavenJava.from components.java - -dependencies { - include(api("com.unrealdinnerbone:UnRealConfig-gson:${unreal_config_version}")) - include(implementation("com.unrealdinnerbone:UnRealConfig-core:${unreal_config_version}")) -} - remapJar { setArchivesBaseName("${project.property("mod_name")}-${project.name}".toLowerCase()) } \ No newline at end of file diff --git a/fabric/src/main/java/com/unrealdinnerbone/trenzalore/platform/FabricPlatformHelper.java b/fabric/src/main/java/com/unrealdinnerbone/trenzalore/platform/FabricPlatformHelper.java index 640c636..1a31981 100644 --- a/fabric/src/main/java/com/unrealdinnerbone/trenzalore/platform/FabricPlatformHelper.java +++ b/fabric/src/main/java/com/unrealdinnerbone/trenzalore/platform/FabricPlatformHelper.java @@ -74,7 +74,7 @@ public void registryRegistryObjects(String modId, RegistryObjects registr @Override @Nullable - public Entity teleportInternal(T entity, ServerLevel level, PortalInfo portalInfo) { + public Entity teleport(T entity, ServerLevel level, PortalInfo portalInfo) { return FabricDimensions.teleport(entity, level, portalInfo); } diff --git a/forge/build.gradle b/forge/build.gradle index 0fafbfc..a1a9cec 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,7 +1,3 @@ -plugins { - id("java-library") -} - multiLoader.forge() { forgeVersion.set("${forge_version}") } @@ -17,19 +13,6 @@ publishing { } } - -dependencies { - api ("com.unrealdinnerbone:UnRealConfig-gson:${unreal_config_version}") -// minecraftEmbed() - minecraftEmbed("com.unrealdinnerbone:UnRealConfig-gson:[${unreal_config_version}]") { - transitive = false - } - minecraftEmbed("com.unrealdinnerbone:UnRealConfig-core:[${unreal_config_version}]") { - transitive = false - } -} - - tasks.jarJar { finalizedBy("reobfJarJar") setArchivesBaseName("${project.property("mod_name")}-${project.name}".toLowerCase()) diff --git a/forge/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreForge.java b/forge/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreForge.java index 3d3b579..a33b44d 100644 --- a/forge/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreForge.java +++ b/forge/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreForge.java @@ -1,7 +1,5 @@ package com.unrealdinnerbone.trenzalore; -import com.unrealdinnerbone.config.ConfigManager; -import com.unrealdinnerbone.config.config.BooleanConfig; import com.unrealdinnerbone.trenzalore.platform.ForgePlatformHelper; import net.minecraftforge.event.BuildCreativeModeTabContentsEvent; import net.minecraftforge.fml.common.Mod; diff --git a/forge/src/main/java/com/unrealdinnerbone/trenzalore/events/ReplaceItemModifier.java b/forge/src/main/java/com/unrealdinnerbone/trenzalore/events/ReplaceItemModifier.java index 2affc8f..9e4d70e 100644 --- a/forge/src/main/java/com/unrealdinnerbone/trenzalore/events/ReplaceItemModifier.java +++ b/forge/src/main/java/com/unrealdinnerbone/trenzalore/events/ReplaceItemModifier.java @@ -2,9 +2,7 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; -import com.unrealdinnerbone.trenzalore.lib.CustomCodecs; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.storage.loot.LootContext; @@ -19,7 +17,7 @@ public class ReplaceItemModifier extends LootModifier { private final ItemStack stack; public static final Codec CODEC = RecordCodecBuilder.create(builder -> codecStart(builder) - .and(CustomCodecs.INGREDIENT.fieldOf("item") + .and(Ingredient.CODEC.fieldOf("item") .forGetter((modifier) -> modifier.ingredient)) .and(ItemStack.CODEC.fieldOf("stack") .forGetter((modifier) -> modifier.stack)) diff --git a/forge/src/main/java/com/unrealdinnerbone/trenzalore/platform/ForgePlatformHelper.java b/forge/src/main/java/com/unrealdinnerbone/trenzalore/platform/ForgePlatformHelper.java index e85e25b..2530156 100644 --- a/forge/src/main/java/com/unrealdinnerbone/trenzalore/platform/ForgePlatformHelper.java +++ b/forge/src/main/java/com/unrealdinnerbone/trenzalore/platform/ForgePlatformHelper.java @@ -69,7 +69,7 @@ public void addItemToCreativeTab(ResourceKey tabResourceKey, Li } @Override - public @Nullable Entity teleportInternal(T entity, ServerLevel level, PortalInfo portalInfo) { + public @Nullable Entity teleport(T entity, ServerLevel level, PortalInfo portalInfo) { return entity.changeDimension(level, new SimpleTeleporter(portalInfo)); } public record SimpleTeleporter(PortalInfo portalInfo) implements ITeleporter { diff --git a/forge/src/main/resources/META-INF/accesstransformer.cfg b/forge/src/main/resources/META-INF/accesstransformer.cfg index 183bc57..57a18a0 100644 --- a/forge/src/main/resources/META-INF/accesstransformer.cfg +++ b/forge/src/main/resources/META-INF/accesstransformer.cfg @@ -1,4 +1,4 @@ -public net.minecraft.advancements.CriteriaTriggers m_10595_(Lnet/minecraft/advancements/CriterionTrigger;)Lnet/minecraft/advancements/CriterionTrigger; +public net.minecraft.advancements.CriteriaTriggers m_10595_(Ljava/lang/String;Lnet/minecraft/advancements/CriterionTrigger;)Lnet/minecraft/advancements/CriterionTrigger; public net.minecraft.world.item.CreativeModeTabs f_256788_ public net.minecraft.world.item.CreativeModeTabs f_256725_ public net.minecraft.world.item.CreativeModeTabs f_256776_ diff --git a/gradle.properties b/gradle.properties index 97c132b..0c9ce5e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Project -mod_version=3.3.10 +mod_version=4.0.0 maven_group=com.unrealdinnerbone mod_name=Trenzalore mod_author=UnRealDinnerbone @@ -7,19 +7,18 @@ mod_id=trenzalore curse_id=870210 # Common -minecraft_version=1.20.1 +minecraft_version=1.20.4 # Forge -forge_version=47.1.46 +forge_version=49.0.13 +neo_version=20.4.70-beta # Fabric -fabric_version=0.83.1+1.20.1 -fabric_loader_version=0.14.21 +fabric_version=0.91.2+1.20.4 +fabric_loader_version=0.15.1 # Gradle org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -#Libs -unreal_config_version=12.3.4 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae0804..a595206 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/neo/build.gradle b/neo/build.gradle new file mode 100644 index 0000000..5158f39 --- /dev/null +++ b/neo/build.gradle @@ -0,0 +1,8 @@ +multiLoader.neo() { + neoVersion.set("${neo_version}") +} + + + +java.toolchain.languageVersion = JavaLanguageVersion.of(17) + diff --git a/neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreForge.java b/neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreForge.java new file mode 100644 index 0000000..0eafb6d --- /dev/null +++ b/neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreForge.java @@ -0,0 +1,22 @@ +package com.unrealdinnerbone.trenzalore; + +import com.unrealdinnerbone.trenzalore.platform.NeoPlatformHelper; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; +import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; + +@Mod(Trenzalore.MOD_ID) +public class TrenzaloreForge { + + public TrenzaloreForge() { + Trenzalore.init(); + FMLJavaModLoadingContext.get().getModEventBus().addListener(TrenzaloreForge::onCreativeTab); + } + + public static void onCreativeTab(BuildCreativeModeTabContentsEvent event) { + if(NeoPlatformHelper.getCreativeTabMap().containsKey(event.getTabKey())) { + NeoPlatformHelper.getCreativeTabMap().get(event.getTabKey()).forEach(supplier -> event.accept(supplier.get())); + } + } + +} \ No newline at end of file diff --git a/neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreNeoRegistry.java b/neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreNeoRegistry.java new file mode 100644 index 0000000..23f730f --- /dev/null +++ b/neo/src/main/java/com/unrealdinnerbone/trenzalore/TrenzaloreNeoRegistry.java @@ -0,0 +1,29 @@ +package com.unrealdinnerbone.trenzalore; + +import com.mojang.serialization.Codec; +import com.unrealdinnerbone.trenzalore.api.platform.services.IRegistry; +import com.unrealdinnerbone.trenzalore.api.registry.Regeneration; +import com.unrealdinnerbone.trenzalore.api.registry.RegistryEntry; +import com.unrealdinnerbone.trenzalore.api.registry.RegistryObjects; +import com.unrealdinnerbone.trenzalore.events.AddItemModifier; +import com.unrealdinnerbone.trenzalore.events.ReplaceItemModifier; +import net.neoforged.neoforge.common.loot.IGlobalLootModifier; +import net.neoforged.neoforge.registries.NeoForgeRegistries; + +import java.util.List; + +public class TrenzaloreNeoRegistry implements IRegistry { + private static final RegistryObjects> GLOBAL_LOOT_MODIFIERS = Regeneration.create(NeoForgeRegistries.Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS); + public static final RegistryEntry> SIMPLE_LOOT_MODIFIER = GLOBAL_LOOT_MODIFIERS.register("replace", () -> ReplaceItemModifier.CODEC); + public static final RegistryEntry> ADD_ITEM_MODIFIER = GLOBAL_LOOT_MODIFIERS.register("add", () -> AddItemModifier.CODEC); + + @Override + public List> getRegistryObjects() { + return List.of(); + } + + @Override + public String getModID() { + return Trenzalore.MOD_ID; + } +} diff --git a/neo/src/main/java/com/unrealdinnerbone/trenzalore/events/AddItemModifier.java b/neo/src/main/java/com/unrealdinnerbone/trenzalore/events/AddItemModifier.java new file mode 100644 index 0000000..4c4bec4 --- /dev/null +++ b/neo/src/main/java/com/unrealdinnerbone/trenzalore/events/AddItemModifier.java @@ -0,0 +1,40 @@ +package com.unrealdinnerbone.trenzalore.events; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; +import net.neoforged.neoforge.common.loot.IGlobalLootModifier; +import net.neoforged.neoforge.common.loot.LootModifier; + +import javax.annotation.Nonnull; + +public class AddItemModifier extends LootModifier { + + private final ItemStack stack; + public static final Codec CODEC = RecordCodecBuilder.create((builder) -> + codecStart(builder) + .and(ItemStack.CODEC.fieldOf("stack") + .forGetter((modifier) -> modifier.stack)) + .apply(builder, AddItemModifier::new)); + + + public AddItemModifier(LootItemCondition[] conditionsIn, ItemStack itemStack) { + super(conditionsIn); + this.stack = itemStack; + } + + @Nonnull + @Override + protected ObjectArrayList doApply(ObjectArrayList generatedLoot, LootContext context) { + generatedLoot.add(stack.copy()); + return generatedLoot; + } + + @Override + public Codec codec() { + return CODEC; + } +} diff --git a/neo/src/main/java/com/unrealdinnerbone/trenzalore/events/ReplaceItemModifier.java b/neo/src/main/java/com/unrealdinnerbone/trenzalore/events/ReplaceItemModifier.java new file mode 100644 index 0000000..f376875 --- /dev/null +++ b/neo/src/main/java/com/unrealdinnerbone/trenzalore/events/ReplaceItemModifier.java @@ -0,0 +1,48 @@ +package com.unrealdinnerbone.trenzalore.events; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; +import net.neoforged.neoforge.common.loot.IGlobalLootModifier; +import net.neoforged.neoforge.common.loot.LootModifier; +import org.jetbrains.annotations.NotNull; + +public class ReplaceItemModifier extends LootModifier { + + private final Ingredient ingredient; + private final ItemStack stack; + public static final Codec CODEC = RecordCodecBuilder.create(builder -> + codecStart(builder) + .and(Ingredient.CODEC_NONEMPTY.fieldOf("item") + .forGetter((modifier) -> modifier.ingredient)) + .and(ItemStack.CODEC.fieldOf("stack") + .forGetter((modifier) -> modifier.stack)) + .apply(builder, ReplaceItemModifier::new)); + + + public ReplaceItemModifier(LootItemCondition[] conditions, Ingredient ingredient, ItemStack itemStack) { + super(conditions); + this.ingredient = ingredient; + this.stack = itemStack; + } + + public ReplaceItemModifier of(Ingredient ingredient, ItemStack itemStack, LootItemCondition... conditions) { + return new ReplaceItemModifier(conditions, ingredient, itemStack); + } + + @NotNull + @Override + protected ObjectArrayList doApply(ObjectArrayList generatedLoot, LootContext context) { + generatedLoot.replaceAll(itemStack -> ingredient.test(itemStack) ? stack.copyWithCount(itemStack.getCount()) : itemStack); + return generatedLoot; + } + + @Override + public Codec codec() { + return CODEC; + } +} diff --git a/neo/src/main/java/com/unrealdinnerbone/trenzalore/platform/NeoPlatformHelper.java b/neo/src/main/java/com/unrealdinnerbone/trenzalore/platform/NeoPlatformHelper.java new file mode 100644 index 0000000..94b053b --- /dev/null +++ b/neo/src/main/java/com/unrealdinnerbone/trenzalore/platform/NeoPlatformHelper.java @@ -0,0 +1,81 @@ +package com.unrealdinnerbone.trenzalore.platform; + +import com.unrealdinnerbone.trenzalore.api.platform.services.IPlatformHelper; +import com.unrealdinnerbone.trenzalore.api.registry.RegistryObjects; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.portal.PortalInfo; +import net.neoforged.fml.ModList; +import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; +import net.neoforged.fml.loading.FMLPaths; +import net.neoforged.neoforge.common.util.ITeleporter; +import net.neoforged.neoforge.registries.DeferredRegister; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Supplier; + +@ApiStatus.Internal +public class NeoPlatformHelper implements IPlatformHelper { + + private static final Map, List>> CREATIVE_TAB_MAP = new HashMap<>(); + + @Override + public String getPlatform() { + return "Neo"; + } + + @Override + public Path getConfigPath() { + return FMLPaths.CONFIGDIR.get(); + } + + @Override + public boolean isModLoaded(String modId) { + return ModList.get().isLoaded(modId); + } + + @Override + public void registryRegistryObjects(String modId, RegistryObjects registryObjects) { + DeferredRegister deferredRegister = DeferredRegister.create(registryObjects.registryKey(), modId); + registryObjects.objects().forEach(registryEntry -> deferredRegister.register(registryEntry.name(), registryEntry.entry())); + deferredRegister.register(FMLJavaModLoadingContext.get().getModEventBus()); + } + + @Override + public void addItemToCreativeTab(ResourceKey tabResourceKey, List> item) { + if(CREATIVE_TAB_MAP.containsKey(tabResourceKey)) { + CREATIVE_TAB_MAP.get(tabResourceKey).addAll(item); + }else { + CREATIVE_TAB_MAP.put(tabResourceKey, new ArrayList<>(item)); + } + } + + @Override + public @Nullable Entity teleport(T entity, ServerLevel level, PortalInfo portalInfo) { + return entity.changeDimension(level, new SimpleTeleporter(portalInfo)); + } + + public record SimpleTeleporter(PortalInfo portalInfo) implements ITeleporter { + + @Override + public @Nullable PortalInfo getPortalInfo(Entity entity, ServerLevel destWorld, Function defaultPortalInfo) { + return portalInfo; + } + } + + @ApiStatus.Internal + public static Map, List>> getCreativeTabMap() { + return CREATIVE_TAB_MAP; + } + +} \ No newline at end of file diff --git a/neo/src/main/resources/META-INF/accesstransformer.cfg b/neo/src/main/resources/META-INF/accesstransformer.cfg new file mode 100644 index 0000000..38c4530 --- /dev/null +++ b/neo/src/main/resources/META-INF/accesstransformer.cfg @@ -0,0 +1,14 @@ +public net.minecraft.advancements.CriteriaTriggers register(Ljava/lang/String;Lnet/minecraft/advancements/CriterionTrigger;)Lnet/minecraft/advancements/CriterionTrigger; +public net.minecraft.world.item.CreativeModeTabs BUILDING_BLOCKS +public net.minecraft.world.item.CreativeModeTabs COLORED_BLOCKS +public net.minecraft.world.item.CreativeModeTabs NATURAL_BLOCKS +public net.minecraft.world.item.CreativeModeTabs FUNCTIONAL_BLOCKS +public net.minecraft.world.item.CreativeModeTabs REDSTONE_BLOCKS +public net.minecraft.world.item.CreativeModeTabs TOOLS_AND_UTILITIES +public net.minecraft.world.item.CreativeModeTabs COMBAT +public net.minecraft.world.item.CreativeModeTabs FOOD_AND_DRINKS +public net.minecraft.world.item.CreativeModeTabs INGREDIENTS +public net.minecraft.world.item.CreativeModeTabs SPAWN_EGGS +public net.minecraft.world.item.CreativeModeTabs OP_BLOCKS +public net.minecraft.world.level.block.entity.BlockEntityType$Builder of(Lnet/minecraft/world/level/block/entity/BlockEntityType$BlockEntitySupplier;[Lnet/minecraft/world/level/block/Block;)Lnet/minecraft/world/level/block/entity/BlockEntityType$Builder; +public net.minecraft.world.level.block.entity.BlockEntityType$BlockEntitySupplier diff --git a/neo/src/main/resources/META-INF/mods.toml b/neo/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..51f6480 --- /dev/null +++ b/neo/src/main/resources/META-INF/mods.toml @@ -0,0 +1,23 @@ +modLoader="javafml" +loaderVersion="[1,)" +license="All Rights Reserved unless stated otherwise. Distribution permission is given to FeedTheBeast and CurseForge for use in modpacks" +[[mods]] +modId="trenzalore" +version="${mod_version}" +displayName="Trenzalore" +logoFile="assets/trenzalore/logo.png" +credits="Mikey for the help!" +authors="UnRealDinnerbone" +description="This mod adds a few small helpers to provide compatibility with Forge / Fabric." +[[dependencies.trenzalore]] + modId="neoforge" + mandatory=true + versionRange="[1.0,)" + ordering="NONE" + side="BOTH" +[[dependencies.trenzalore]] + modId="minecraft" + mandatory=true + versionRange="[${minecraft_version}]" + ordering="NONE" + side="BOTH" diff --git a/neo/src/main/resources/META-INF/services/com.unrealdinnerbone.trenzalore.api.platform.services.IPlatformHelper b/neo/src/main/resources/META-INF/services/com.unrealdinnerbone.trenzalore.api.platform.services.IPlatformHelper new file mode 100644 index 0000000..9d2763a --- /dev/null +++ b/neo/src/main/resources/META-INF/services/com.unrealdinnerbone.trenzalore.api.platform.services.IPlatformHelper @@ -0,0 +1 @@ +com.unrealdinnerbone.trenzalore.platform.NeoPlatformHelper \ No newline at end of file diff --git a/neo/src/main/resources/META-INF/services/com.unrealdinnerbone.trenzalore.api.platform.services.IRegistry b/neo/src/main/resources/META-INF/services/com.unrealdinnerbone.trenzalore.api.platform.services.IRegistry new file mode 100644 index 0000000..8b02861 --- /dev/null +++ b/neo/src/main/resources/META-INF/services/com.unrealdinnerbone.trenzalore.api.platform.services.IRegistry @@ -0,0 +1,2 @@ +com.unrealdinnerbone.trenzalore.TrenzaloreNeoRegistry +com.unrealdinnerbone.trenzalore.TestItems diff --git a/settings.gradle b/settings.gradle index dc6ff87..6ce624f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,21 @@ pluginManagement { name = 'Creeperhost' url = 'https://maven.creeperhost.net/' } + maven { + name = 'Sponge Snapshots' + url = 'https://repo.spongepowered.org/repository/maven-public/' + } + } + + + plugins { + id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.7" apply(false) + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' } + } -include("common", "fabric", "forge") \ No newline at end of file + + + +include("common", "neo", "fabric", "forge") \ No newline at end of file