Skip to content

Commit

Permalink
Fix Radio villager trades in NEI (#22)
Browse files Browse the repository at this point in the history
* Fix Radio villager trades

* Update dependencies.gradle
  • Loading branch information
kuba6000 authored Aug 29, 2024
1 parent fdbe70c commit bb73303
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ dependencies {
compileOnly('openperipheral:OpenPeripheralCore-API:3.4.1')
compileOnly('com.github.GTNewHorizons:NotEnoughItems:2.6.11-GTNH:dev')
compileOnly('curse.maven:computercraft-67504:2269339')
compileOnly('com.github.GTNewHorizons:Mobs-Info:0.4.5-GTNH:dev')
}
33 changes: 32 additions & 1 deletion src/main/java/openblocks/common/RadioVillagerTradeManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package openblocks.common;

import static com.kuba6000.mobsinfo.api.VillagerTrade.create;
import static com.kuba6000.mobsinfo.api.VillagerTrade.createItem;

import java.util.ArrayList;
import java.util.Random;

import javax.annotation.Nonnull;

import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
Expand All @@ -11,10 +17,15 @@
import net.minecraft.village.MerchantRecipeList;
import net.minecraftforge.oredict.OreDictionary;

import com.kuba6000.mobsinfo.api.IVillagerInfoProvider;
import com.kuba6000.mobsinfo.api.VillagerTrade;

import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler;
import openblocks.Config;

public class RadioVillagerTradeManager implements IVillageTradeHandler {
@Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IVillagerInfoProvider", modid = "mobsinfo")
public class RadioVillagerTradeManager implements IVillageTradeHandler, IVillagerInfoProvider {

private static ItemStack randomItemAmount(Random random, Item item, int min, int max) {
int amount = random.nextInt(max - min) + min;
Expand All @@ -39,4 +50,24 @@ public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeL
.addToListWithCheck(new MerchantRecipe(randomEmeralds(random, 3, 7), new ItemStack(Blocks.jukebox)));
}

@Optional.Method(modid = "mobsinfo")
@Override
public void provideTrades(@Nonnull EntityVillager villager, int profession,
@Nonnull ArrayList<VillagerTrade> trades) {
if (Config.radioVillagerRecords) {
for (ItemStack record : OreDictionary.getOres("record")) {
trades.add(
create(createItem(Items.emerald).withPossibleSizes(7, 15), createItem(record))
.withChance(0.01d));
}
}
trades.add(
create(
createItem(Items.emerald).withPossibleSizes(1, 2),
createItem(Item.getItemFromBlock(Blocks.noteblock))).withChance(0.5d));
trades.add(
create(
createItem(Items.emerald).withPossibleSizes(3, 7),
createItem(Item.getItemFromBlock(Blocks.jukebox))).withChance(0.25d));
}
}

0 comments on commit bb73303

Please sign in to comment.