Skip to content

Commit

Permalink
Add trades to AE2 villager
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Sep 26, 2023
1 parent b9b8244 commit 3b3c2bb
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 6 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/gripe/_90/megacells/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/java/gripe/_90/megacells/core/Platform.java
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -10,4 +11,6 @@ public interface Platform {
boolean isAddonLoaded(Addons addon);

void initCompression();

void addVillagerTrade(ItemLike item, int cost, int quantity, int xp);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
}
4 changes: 2 additions & 2 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,7 +25,7 @@ loom {
}

forge {
mixinConfig("$modId.mixins.json")
mixinConfig("$modId.forge.mixins.json")
}
}

Expand Down
22 changes: 22 additions & 0 deletions forge/src/main/java/gripe/_90/megacells/forge/ForgePlatform.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
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;
import net.minecraftforge.fml.ModList;
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;
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")

Expand Down

0 comments on commit 3b3c2bb

Please sign in to comment.