Skip to content

Commit

Permalink
Catch custom villager recipes when adding vanilla villagers (#85)
Browse files Browse the repository at this point in the history
* Catch custom villager recipes when adding vanilla villagers

* Smith -> Blacksmith
  • Loading branch information
kuba6000 committed Oct 2, 2024
1 parent e621db8 commit 71178db
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.kuba6000.mobsinfo.api.VillagerRecipe;
import com.kuba6000.mobsinfo.api.VillagerTrade;
import com.kuba6000.mobsinfo.api.utils.ItemID;
import com.kuba6000.mobsinfo.api.utils.ModUtils;
import com.kuba6000.mobsinfo.config.Config;
import com.kuba6000.mobsinfo.nei.VillagerTradesHandler;
import com.kuba6000.mobsinfo.network.LoadConfigPacket;
Expand Down Expand Up @@ -53,6 +54,38 @@ public static void generateVillagerTrades() {

// vanilla recipes?

ModUtils.TriConsumer<ArrayList<VillagerTrade>, EntityVillager, Integer> detectCustomRecipes = (recipes,
villager, villagerID) -> {
try {
frand.newRound();

TradeList trades = new TradeList();
TradeCollector collector = new TradeCollector();
boolean second = false;
do {
MerchantRecipeList list = new MerchantRecipeList();
VillagerRegistry.manageVillagerTrades(list, villager, villagerID, world.rand);
collector.collectTrades(trades, list, frand.chance);

if (second && frand.chance < 0.0000001d) {
LOG.warn("Skipping " + villagerID + "(CustomHandler) because it's too randomized");
break;
}
second = true;
} while (frand.nextRound());
frand.newRound();
collector.newRound();

if (!trades.itemsToTrade.isEmpty()) {
for (TradeInstance value : trades.itemsToTrade.values()) {
recipes.add(new VillagerTrade(value.i1, value.i2, value.o, value.chance));
}
}
} catch (Throwable e) {
e.printStackTrace();
}
};

{ // profession 0
EntityVillager entity = new EntityVillager(world);

Expand Down Expand Up @@ -80,6 +113,8 @@ public static void generateVillagerTrades() {
new ItemStack(Items.flint, 5, 0),
0.5d));

detectCustomRecipes.accept(recipes, entity, 0);

VillagerRecipe.recipes.put(0, new VillagerRecipe(recipes, 0, entity));
}

Expand All @@ -104,6 +139,8 @@ public static void generateVillagerTrades() {
new VillagerTrade.TradeItem(new ItemStack(Items.book), null, 1),
0.07d));

detectCustomRecipes.accept(recipes, entity, 1);

VillagerRecipe.recipes.put(1, new VillagerRecipe(recipes, 1, entity));
}

Expand All @@ -130,6 +167,8 @@ public static void generateVillagerTrades() {
0.05d));
}

detectCustomRecipes.accept(recipes, entity, 2);

VillagerRecipe.recipes.put(2, new VillagerRecipe(recipes, 2, entity));
}

Expand Down Expand Up @@ -166,6 +205,8 @@ public static void generateVillagerTrades() {
recipes.add(new VillagerTrade(Items.emerald, null, Items.chainmail_chestplate, 0.1d));
recipes.add(new VillagerTrade(Items.emerald, null, Items.chainmail_leggings, 0.1d));

detectCustomRecipes.accept(recipes, entity, 3);

VillagerRecipe.recipes.put(3, new VillagerRecipe(recipes, 3, entity));
}

Expand All @@ -186,10 +227,12 @@ public static void generateVillagerTrades() {
recipes.add(new VillagerTrade(Items.emerald, null, Items.cooked_porkchop, 0.3d));
recipes.add(new VillagerTrade(Items.emerald, null, Items.cooked_beef, 0.3d));

detectCustomRecipes.accept(recipes, entity, 4);

VillagerRecipe.recipes.put(4, new VillagerRecipe(recipes, 4, entity));
}

// custom handlers
// custom villagers

MobRecipeLoader.isInGenerationProcess = true;
for (Integer id : VillagerRegistry.getRegisteredVillagers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public VillagerCachedRecipe(
this.mod = "Minecraft";
break;
case 3:
this.profession = "Smith";
this.profession = "Blacksmith";
this.mod = "Minecraft";
break;
case 4:
Expand Down

0 comments on commit 71178db

Please sign in to comment.