From 3b3c2bb375f89f740cc275788e4e7e7665b2fb09 Mon Sep 17 00:00:00 2001 From: 90 Date: Tue, 26 Sep 2023 18:20:38 +0300 Subject: [PATCH] Add trades to AE2 villager --- build.gradle.kts | 4 ++-- .../java/gripe/_90/megacells/MEGACells.java | 3 +++ .../gripe/_90/megacells/core/Platform.java | 3 +++ .../_90/megacells/fabric/FabricPlatform.java | 13 +++++++++++ forge/build.gradle.kts | 4 ++-- ...mixins.json => megacells.data.mixins.json} | 0 .../_90/megacells/forge/ForgePlatform.java | 22 +++++++++++++++++++ ...ixins.json => megacells.forge.mixins.json} | 0 settings.gradle.kts | 4 ++-- 9 files changed, 47 insertions(+), 6 deletions(-) rename forge/src/data/resources/{megacells-data.mixins.json => megacells.data.mixins.json} (100%) rename forge/src/main/resources/{megacells.mixins.json => megacells.forge.mixins.json} (100%) diff --git a/build.gradle.kts b/build.gradle.kts index be918a29..fabdf5be 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ import net.fabricmc.loom.task.RemapJarTask plugins { java `maven-publish` - alias(libs.plugins.archLoom) apply false + alias(libs.plugins.loom) apply false alias(libs.plugins.vineflower) apply false alias(libs.plugins.architectury) alias(libs.plugins.shadow) @@ -36,7 +36,7 @@ tasks { subprojects { apply(plugin = "java") apply(plugin = rootProject.libs.plugins.architectury.get().pluginId) - apply(plugin = rootProject.libs.plugins.archLoom.get().pluginId) + apply(plugin = rootProject.libs.plugins.loom.get().pluginId) apply(plugin = rootProject.libs.plugins.vineflower.get().pluginId) apply(plugin = rootProject.libs.plugins.spotless.get().pluginId) diff --git a/common/src/main/java/gripe/_90/megacells/MEGACells.java b/common/src/main/java/gripe/_90/megacells/MEGACells.java index d8e299be..665ba442 100644 --- a/common/src/main/java/gripe/_90/megacells/MEGACells.java +++ b/common/src/main/java/gripe/_90/megacells/MEGACells.java @@ -60,6 +60,9 @@ public static void initCommon() { MEGACells.PLATFORM.initCompression(); GridServices.register(DecompressionService.class, DecompressionService.class); + + MEGACells.PLATFORM.addVillagerTrade(MEGAItems.SKY_STEEL_INGOT, 8, 3, 20); + MEGACells.PLATFORM.addVillagerTrade(MEGAItems.ACCUMULATION_PROCESSOR_PRESS, 40, 1, 50); } private static void initStorageCells() { diff --git a/common/src/main/java/gripe/_90/megacells/core/Platform.java b/common/src/main/java/gripe/_90/megacells/core/Platform.java index fe6d0561..89ba51d6 100644 --- a/common/src/main/java/gripe/_90/megacells/core/Platform.java +++ b/common/src/main/java/gripe/_90/megacells/core/Platform.java @@ -1,6 +1,7 @@ package gripe._90.megacells.core; import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.level.ItemLike; public interface Platform { Loaders getLoader(); @@ -10,4 +11,6 @@ public interface Platform { boolean isAddonLoaded(Addons addon); void initCompression(); + + void addVillagerTrade(ItemLike item, int cost, int quantity, int xp); } diff --git a/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java b/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java index 16c69274..d29f078c 100644 --- a/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java +++ b/fabric/src/main/java/gripe/_90/megacells/fabric/FabricPlatform.java @@ -2,8 +2,13 @@ import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; +import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.world.entity.npc.VillagerTrades; import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.level.ItemLike; + +import appeng.init.InitVillager; import gripe._90.megacells.core.Addons; import gripe._90.megacells.core.Loaders; @@ -34,4 +39,12 @@ public void initCompression() { if (success) CompressionService.INSTANCE.loadRecipes(server.getRecipeManager(), server.registryAccess()); }); } + + @Override + public void addVillagerTrade(ItemLike item, int cost, int quantity, int xp) { + TradeOfferHelper.registerVillagerOffers( + InitVillager.PROFESSION, + 5, + builder -> builder.add(new VillagerTrades.ItemsForEmeralds(item.asItem(), cost, quantity, xp))); + } } diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 15ad1315..122427d8 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -11,7 +11,7 @@ loom { programArgs("--output", file("src/generated/resources").absolutePath) programArgs("--existing", project(":common").file("src/main/resources").absolutePath) programArgs("--existing", file("src/main/resources").absolutePath) - programArgs("--mixin.config", "megacells-data.mixins.json") + programArgs("--mixin.config", "$modId.data.mixins.json") @Suppress("UnstableApiUsage") mods { @@ -25,7 +25,7 @@ loom { } forge { - mixinConfig("$modId.mixins.json") + mixinConfig("$modId.forge.mixins.json") } } diff --git a/forge/src/data/resources/megacells-data.mixins.json b/forge/src/data/resources/megacells.data.mixins.json similarity index 100% rename from forge/src/data/resources/megacells-data.mixins.json rename to forge/src/data/resources/megacells.data.mixins.json diff --git a/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java b/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java index bedce42d..f0fffdf2 100644 --- a/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java +++ b/forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java @@ -1,6 +1,15 @@ package gripe._90.megacells.forge; +import org.apache.commons.lang3.ArrayUtils; + +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +import net.minecraft.world.entity.npc.VillagerTrades; import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.trading.MerchantOffer; +import net.minecraft.world.level.ItemLike; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.OnDatapackSyncEvent; import net.minecraftforge.event.server.ServerStartedEvent; @@ -8,6 +17,8 @@ import net.minecraftforge.fml.loading.LoadingModList; import net.minecraftforge.fml.loading.moddiscovery.ModInfo; +import appeng.init.InitVillager; + import gripe._90.megacells.core.Addons; import gripe._90.megacells.core.Loaders; import gripe._90.megacells.core.Platform; @@ -51,4 +62,15 @@ public void initCompression() { } }); } + + @Override + public void addVillagerTrade(ItemLike item, int cost, int quantity, int xp) { + var offers = VillagerTrades.TRADES.computeIfAbsent(InitVillager.PROFESSION, k -> new Int2ObjectOpenHashMap<>()); + var masterEntries = offers.computeIfAbsent(5, k -> new VillagerTrades.ItemListing[0]); + masterEntries = ArrayUtils.add( + masterEntries, + (i, j) -> new MerchantOffer( + new ItemStack(Items.EMERALD, cost), new ItemStack(item, quantity), 12, xp, 0.05F)); + offers.put(5, masterEntries); + } } diff --git a/forge/src/main/resources/megacells.mixins.json b/forge/src/main/resources/megacells.forge.mixins.json similarity index 100% rename from forge/src/main/resources/megacells.mixins.json rename to forge/src/main/resources/megacells.forge.mixins.json diff --git a/settings.gradle.kts b/settings.gradle.kts index 2258d076..c4e1eec8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -10,7 +10,7 @@ pluginManagement { dependencyResolutionManagement { versionCatalogs { create("libs") { - plugin("archLoom", "dev.architectury.loom").version("1.3-SNAPSHOT") + plugin("loom", "dev.architectury.loom").version("1.3-SNAPSHOT") plugin("architectury", "architectury-plugin").version("3.4-SNAPSHOT") plugin("vineflower", "io.github.juuxel.loom-vineflower").version("1.11.0") plugin("shadow", "com.github.johnrengelman.shadow").version("8.1.1") @@ -24,7 +24,7 @@ dependencyResolutionManagement { library("fabric-api", "net.fabricmc.fabric-api", "fabric-api").version("0.83.1+$minecraftVersion") library("forge", "net.minecraftforge", "forge").version("$minecraftVersion-47.1.3") - version("ae2", "15.0.10") + version("ae2", "15.0.11") library("ae2-fabric", "appeng", "appliedenergistics2-fabric").versionRef("ae2") library("ae2-forge", "appeng", "appliedenergistics2-forge").versionRef("ae2")