Skip to content

Commit

Permalink
Switch to new event for villager trades
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Dec 22, 2024
1 parent 1428620 commit 10ecbcf
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/main/java/gripe/_90/megacells/MEGACells.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import java.util.List;

import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;

import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.npc.VillagerTrades;
import net.minecraft.world.item.Item;
Expand All @@ -23,6 +20,8 @@
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.village.VillagerTradesEvent;

import appeng.api.AECapabilities;
import appeng.api.features.HotkeyAction;
Expand Down Expand Up @@ -66,9 +65,9 @@ public MEGACells(ModContainer container, IEventBus eventBus) {
eventBus.addListener(MEGACells::initUpgrades);
eventBus.addListener(MEGACells::initStorageCells);
eventBus.addListener(MEGACells::initCapabilities);
eventBus.addListener(MEGACells::initVillagerTrades);

CompressionService.init();
NeoForge.EVENT_BUS.addListener(MEGACells::initVillagerTrades);

container.registerConfig(ModConfig.Type.COMMON, MEGAConfig.SPEC);
}
Expand Down Expand Up @@ -158,21 +157,17 @@ private static void initStorageCells(FMLCommonSetupEvent event) {
});
}

private static void initVillagerTrades(FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
addVillagerTrade(MEGAItems.SKY_STEEL_INGOT, 8, 3, 20);
addVillagerTrade(MEGAItems.ACCUMULATION_PROCESSOR_PRESS, 40, 1, 50);
});
private static void initVillagerTrades(VillagerTradesEvent event) {
if (event.getType() == InitVillager.PROFESSION) {
var trades = event.getTrades().get(5);
trades.add(villagerTrade(MEGAItems.SKY_STEEL_INGOT, 8, 3, 20));
trades.add(villagerTrade(MEGAItems.ACCUMULATION_PROCESSOR_PRESS, 40, 1, 50));
}
}

private static 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 ItemCost(Items.EMERALD, cost), new ItemStack(item, quantity), 12, xp, 0.05F));
offers.put(5, masterEntries);
private static VillagerTrades.ItemListing villagerTrade(ItemLike item, int cost, int quantity, int xp) {
return (entity, random) ->
new MerchantOffer(new ItemCost(Items.EMERALD, cost), new ItemStack(item, quantity), 12, xp, 0.05F);
}

@SuppressWarnings("UnstableApiUsage")
Expand Down

0 comments on commit 10ecbcf

Please sign in to comment.