From 225abed5b42bde79ec0fea28b841c6fea8db2f49 Mon Sep 17 00:00:00 2001 From: "Joseph T. McQuigg" Date: Wed, 25 Dec 2024 22:30:17 -0500 Subject: [PATCH] Wandering trades, Trades Config Rework (#184) * Start on WanderingTrades Signed-off-by: Joseph T. McQuigg * Change Trades Config Signed-off-by: Joseph T. McQuigg * Add Mushrooms, lily pads, and flowers to wandering traders Signed-off-by: Joseph T. McQuigg * Update Config stuff Signed-off-by: Joseph T. McQuigg * More Trade Config Signed-off-by: Joseph T. McQuigg * Adjustments Signed-off-by: Joseph T. McQuigg * ChangeLog Signed-off-by: Joseph T. McQuigg * Fix some Issues with Null Issues Signed-off-by: Joseph T. McQuigg --------- Signed-off-by: Joseph T. McQuigg --- CHANGELOG.md | 2 + .../biomeswevegone/config/ConfigLoader.java | 4 + .../biomeswevegone/config/ConfigUtils.java | 52 ++++++++++++ .../config/configs/BWGTradesConfig.java | 79 ++++-------------- .../config/configs/BWGWorldGenConfig.java | 82 ++++++------------- .../world/entity/npc/BWGVillagerTrades.java | 72 ++++++++++------ .../fabric/VanillaCompatFabric.java | 18 +++- .../forge/BiomesWeveGoneForge.java | 1 + .../forge/VanillaCompatForge.java | 21 ++++- 9 files changed, 183 insertions(+), 148 deletions(-) create mode 100644 Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigUtils.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 68f1fbcd8..6a37c8646 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ - Slight Change to FruitBlockProcessor#finalizeProcessing to be more Efficient - Use SpawnPlacementRegisterEvent on Forge to Register Entity Spawn Placements - Add Config to Enable/Disable Spawning of Oddion and Man O War +- Add BWG Items to Wandering Trader Trades +- New BWG Trades Config with Wandering Trader Options, and Option to disable Forager Trades # 1.4.4 - Add Russian Translations (ru_ru) (Credits: j-tap) diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigLoader.java b/Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigLoader.java index 1d84f7be4..f4ec3c759 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigLoader.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigLoader.java @@ -26,6 +26,10 @@ public class ConfigLoader { */ public static T loadConfig(@NotNull Class clazz, String name) { try { + try { + Files.delete(PlatformHandler.PLATFORM_HANDLER.configPath().resolve(name + ".json5")); + } catch (Exception ignored) {} + Path configPath = PlatformHandler.PLATFORM_HANDLER.configPath().resolve(name + ".json"); T value = clazz.getConstructor().newInstance(); diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigUtils.java b/Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigUtils.java new file mode 100644 index 000000000..cae2291f1 --- /dev/null +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/config/ConfigUtils.java @@ -0,0 +1,52 @@ +package net.potionstudios.biomeswevegone.config; + +import com.mojang.datafixers.util.Pair; +import com.mojang.serialization.Codec; +import corgitaco.corgilib.serialization.jankson.JanksonJsonOps; +import corgitaco.corgilib.shadow.blue.endless.jankson.Jankson; +import corgitaco.corgilib.shadow.blue.endless.jankson.JsonElement; +import corgitaco.corgilib.shadow.blue.endless.jankson.JsonGrammar; +import corgitaco.corgilib.shadow.blue.endless.jankson.JsonObject; +import corgitaco.corgilib.shadow.blue.endless.jankson.api.SyntaxError; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class ConfigUtils { + public static T loadConfig(Path path, Codec codec, T defaultConfig) { + if (!path.toFile().exists()) { + createDefaultFile(path, codec, defaultConfig); + return defaultConfig; + } + + Jankson build = new Jankson.Builder().build(); + try { + String configFile = Files.readString(path).strip(); + JsonObject load = build.load(configFile); + Pair configResult = codec.decode(JanksonJsonOps.INSTANCE, load).result().orElseThrow(); + T config = configResult.getFirst(); + createDefaultFile(path, codec, config); + return config; + } catch (IOException | SyntaxError e) { + throw new RuntimeException(e); + } + } + + public static void createDefaultFile(Path path, Codec codec, T config) { + JsonElement jsonElement = codec.encodeStart(JanksonJsonOps.INSTANCE, config).result().orElseThrow(); + String json = jsonElement.toJson(JsonGrammar.JSON5); + try { + Files.createDirectories(path.getParent()); + Files.writeString(path, json); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public record CommentValue(String comment, T value) { + public static CommentValue of(String comment, T value) { + return new CommentValue<>(comment, value); + } + } +} diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGTradesConfig.java b/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGTradesConfig.java index a559e2b77..81adc5c64 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGTradesConfig.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGTradesConfig.java @@ -1,73 +1,28 @@ package net.potionstudios.biomeswevegone.config.configs; -import com.google.common.base.Suppliers; -import com.mojang.datafixers.util.Pair; -import com.mojang.serialization.Codec; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import corgitaco.corgilib.serialization.codec.CommentedCodec; -import corgitaco.corgilib.serialization.jankson.JanksonJsonOps; -import corgitaco.corgilib.shadow.blue.endless.jankson.Jankson; -import corgitaco.corgilib.shadow.blue.endless.jankson.JsonElement; -import corgitaco.corgilib.shadow.blue.endless.jankson.JsonGrammar; -import corgitaco.corgilib.shadow.blue.endless.jankson.JsonObject; -import corgitaco.corgilib.shadow.blue.endless.jankson.api.SyntaxError; -import net.potionstudios.biomeswevegone.PlatformHandler; -import org.jetbrains.annotations.NotNull; +import net.potionstudios.biomeswevegone.config.ConfigLoader; +import net.potionstudios.biomeswevegone.config.ConfigUtils; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.function.Supplier; +public class BWGTradesConfig { -public record BWGTradesConfig(boolean enableTrades, boolean enableVanillaTradeAdditions) { + public static final BWGTradesConfig INSTANCE = ConfigLoader.loadConfig(BWGTradesConfig.class, "trades"); - private static final Path PATH = PlatformHandler.PLATFORM_HANDLER.configPath().resolve("trades.json5"); + public BWGTrades trades = new BWGTrades(); - @NotNull - public static Supplier INSTANCE = Suppliers.memoize(BWGTradesConfig::getOrCreateConfigFromDisk); + public static class BWGTrades { + public ConfigUtils.CommentValue disableTrades = ConfigUtils.CommentValue.of("Disable All BWG Trades, If this is set to true none of the values below will matter", false); + } - private static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - CommentedCodec.of(Codec.BOOL, "enable_trades", "Whether to enable BWG Villager Trades").orElse(true).forGetter(config -> true), - CommentedCodec.of(Codec.BOOL, "enable_vanilla_trade_additions", "Whether to add BWG Villager Trades to Vanilla Villagers").orElse(true).forGetter(config -> true) - ).apply(instance, BWGTradesConfig::new)); + public BWGVillagerTradesConfig villagerTrades = new BWGVillagerTradesConfig(); - private static BWGTradesConfig createDefault() { - return new BWGTradesConfig(true, true); - } + public static class BWGVillagerTradesConfig { + public ConfigUtils.CommentValue allowBWGForagerTrades = ConfigUtils.CommentValue.of("Allow BWG Forager Profession Trades", true); + public ConfigUtils.CommentValue enableBWGVanillaProfessionTradeAdditions = ConfigUtils.CommentValue.of("Allows BWG Items to be added to Vanilla Profession Trades", true); + } - private static BWGTradesConfig getOrCreateConfigFromDisk() { - BWGTradesConfig defaultConfig = createDefault(); + public BWGWanderingTraderTradesConfig wanderingTraderTrades = new BWGWanderingTraderTradesConfig(); - if (!PATH.toFile().exists()) { - createDefaultFile(defaultConfig); - return defaultConfig; - } - - Jankson build = new Jankson.Builder().build(); - try { - String configFile = Files.readString(PATH).stripTrailing().trim().strip().stripLeading(); - JsonObject load = build.load(configFile); - Pair configResult = CODEC.decode(JanksonJsonOps.INSTANCE, load).result().orElseThrow(); - BWGTradesConfig config = configResult.getFirst(); - - BWGTradesConfig toCreate = new BWGTradesConfig(config.enableTrades, config.enableVanillaTradeAdditions); - - createDefaultFile(toCreate); - return toCreate; - - } catch (IOException | SyntaxError e) { - throw new RuntimeException(e); - } - } - - private static void createDefaultFile(BWGTradesConfig tradesConfig) { - JsonElement jsonElement = CODEC.encodeStart(JanksonJsonOps.INSTANCE, tradesConfig).result().orElseThrow(); - String json = jsonElement.toJson(JsonGrammar.JSON5); - try { - Files.createDirectories(PATH.getParent()); - Files.writeString(PATH, json); - } catch (IOException e) { - throw new RuntimeException(e); - } - } + public static class BWGWanderingTraderTradesConfig { + public ConfigUtils.CommentValue enableBWGItemsTrades = ConfigUtils.CommentValue.of("Allows BWG Items to be added to Wandering Trader Offerings", true); + } } diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGWorldGenConfig.java b/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGWorldGenConfig.java index 639fffe44..a732f4513 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGWorldGenConfig.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/config/configs/BWGWorldGenConfig.java @@ -1,52 +1,45 @@ package net.potionstudios.biomeswevegone.config.configs; import com.google.common.base.Suppliers; -import com.mojang.datafixers.util.Pair; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import corgitaco.corgilib.serialization.codec.CommentedCodec; -import corgitaco.corgilib.serialization.jankson.JanksonJsonOps; -import corgitaco.corgilib.shadow.blue.endless.jankson.Jankson; -import corgitaco.corgilib.shadow.blue.endless.jankson.JsonElement; -import corgitaco.corgilib.shadow.blue.endless.jankson.JsonGrammar; -import corgitaco.corgilib.shadow.blue.endless.jankson.JsonObject; -import corgitaco.corgilib.shadow.blue.endless.jankson.api.SyntaxError; import it.unimi.dsi.fastutil.objects.Object2BooleanMap; import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; -import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.potionstudios.biomeswevegone.PlatformHandler; +import net.potionstudios.biomeswevegone.config.ConfigUtils; import net.potionstudios.biomeswevegone.world.level.levelgen.biome.BWGBiomes; +import net.potionstudios.biomeswevegone.world.level.levelgen.feature.placed.BWGOverworldTreePlacedFeatures; +import net.potionstudios.biomeswevegone.world.level.levelgen.feature.placed.BWGVanillaPlacedFeatures; import org.jetbrains.annotations.NotNull; -import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; import java.util.function.Supplier; public record BWGWorldGenConfig(Map, Boolean> enabledBiomes, int regionWeight, - boolean vanillaAdditions) { + boolean vanillaAdditions, Map, Boolean> vanillaFeatures) { - public static final Path PATH = PlatformHandler.PLATFORM_HANDLER.configPath().resolve("world_generation.json5"); + private static final Path PATH = PlatformHandler.PLATFORM_HANDLER.configPath().resolve("world_generation.json5"); @NotNull public static Supplier INSTANCE = Suppliers.memoize(BWGWorldGenConfig::getOrCreateConfigFromDisk); - public static final Codec CODEC = RecordCodecBuilder.create(instance -> + private static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( CommentedCodec.of(Codec.unboundedMap(ResourceKey.codec(Registries.BIOME), Codec.BOOL), "enabled_biomes", "Which biomes are enabled, if disabled the biome will default to its vanilla counterpart for the given region").orElse(getDefaultBiomes()).forGetter(BWGWorldGenConfig::enabledBiomes), CommentedCodec.of(Codec.INT, "region_weight", "How much each BWG region weighs. This weight applies to all 3 BWG Regions").orElse(8).forGetter(BWGWorldGenConfig::regionWeight), - CommentedCodec.of(Codec.BOOL, "vanilla_additions", "Whether to add bwg flowers and features to Vanilla Biomes (Config Option for Fabric Only)").orElse(true).forGetter(config -> true) + CommentedCodec.of(Codec.BOOL, "vanilla_additions", "Whether to add bwg flowers and features to Vanilla Biomes (Config Option for Fabric Only)").orElse(true).forGetter(config -> true), + CommentedCodec.of(Codec.unboundedMap(ResourceKey.codec(Registries.PLACED_FEATURE), Codec.BOOL), "enabled_vanilla_additions", "BWG Features that we add to Vanilla Biomes").orElse(getVanillaPlacedFeatureAdditions()).forGetter(BWGWorldGenConfig::vanillaFeatures) ).apply(instance, BWGWorldGenConfig::new) ); - public static BWGWorldGenConfig createDefault() { - Object2BooleanMap> enabledBiomes = getDefaultBiomes(); - - return new BWGWorldGenConfig(enabledBiomes, 8, true); + private static BWGWorldGenConfig createDefault() { + return new BWGWorldGenConfig(getDefaultBiomes(), 8, true, getVanillaPlacedFeatureAdditions()); } private static @NotNull Object2BooleanMap> getDefaultBiomes() { @@ -55,51 +48,22 @@ public static BWGWorldGenConfig createDefault() { enabledBiomes.put(biomeResourceKey, true); } - enabledBiomes.put(BWGBiomes.ERODED_BOREALIS, false); + enabledBiomes.replace(BWGBiomes.ERODED_BOREALIS, false); return enabledBiomes; } - public static BWGWorldGenConfig getOrCreateConfigFromDisk() { - BWGWorldGenConfig defaultWorldGenConfig = createDefault(); - - if (!PATH.toFile().exists()) { - createDefaultFile(defaultWorldGenConfig); - return defaultWorldGenConfig; - } else { - - Jankson build = new Jankson.Builder().build(); - try { - String configFile = Files.readString(PATH).stripTrailing().trim().strip().stripLeading(); - JsonObject load = build.load(configFile); - Pair configResult = CODEC.decode(JanksonJsonOps.INSTANCE, load).result().orElseThrow(); - BWGWorldGenConfig config = configResult.getFirst(); - - - Map, Boolean> temporary = new Reference2ObjectOpenHashMap<>(); - - temporary.putAll(defaultWorldGenConfig.enabledBiomes); - temporary.putAll(config.enabledBiomes); + private static @NotNull Object2BooleanMap> getVanillaPlacedFeatureAdditions() { + Object2BooleanMap> enabledFeatures = new Object2BooleanOpenHashMap<>(); + enabledFeatures.put(BWGVanillaPlacedFeatures.FLOWER_DEFAULT, true); + enabledFeatures.put(BWGVanillaPlacedFeatures.FLOWER_PLAINS, true); + enabledFeatures.put(BWGVanillaPlacedFeatures.FOREST_FLOWERS, true); + enabledFeatures.put(BWGVanillaPlacedFeatures.FLOWER_WARM, true); + enabledFeatures.put(BWGOverworldTreePlacedFeatures.PALM_TREES, true); - BWGWorldGenConfig toCreate = new BWGWorldGenConfig(temporary, config.regionWeight, config.vanillaAdditions); - - createDefaultFile(toCreate); - - return toCreate; - - } catch (IOException | SyntaxError e) { - throw new RuntimeException(e); - } - } + return enabledFeatures; } - private static void createDefaultFile(BWGWorldGenConfig defaultWorldGenConfig) { - JsonElement jsonElement = CODEC.encodeStart(JanksonJsonOps.INSTANCE, defaultWorldGenConfig).result().orElseThrow(); - String json = jsonElement.toJson(JsonGrammar.JSON5); - try { - Files.createDirectories(PATH.getParent()); - Files.writeString(PATH, json); - } catch (IOException e) { - throw new RuntimeException(e); - } + private static BWGWorldGenConfig getOrCreateConfigFromDisk() { + return ConfigUtils.loadConfig(PATH, CODEC, createDefault()); } -} +} \ No newline at end of file diff --git a/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/npc/BWGVillagerTrades.java b/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/npc/BWGVillagerTrades.java index 37bbbe36d..9ae236a7d 100644 --- a/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/npc/BWGVillagerTrades.java +++ b/Common/src/main/java/net/potionstudios/biomeswevegone/world/entity/npc/BWGVillagerTrades.java @@ -9,10 +9,15 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.trading.MerchantOffer; import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.block.FlowerBlock; +import net.minecraft.world.level.block.SaplingBlock; import net.potionstudios.biomeswevegone.config.configs.BWGTradesConfig; import net.potionstudios.biomeswevegone.world.item.BWGItems; import net.potionstudios.biomeswevegone.world.level.block.BWGBlocks; +import net.potionstudios.biomeswevegone.world.level.block.sand.BWGSandSet; +import net.potionstudios.biomeswevegone.world.level.block.wood.BWGWood; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -22,30 +27,31 @@ public class BWGVillagerTrades { public static final Map>> TRADES = new HashMap<>(); public static void makeTrades() { - TRADES.put(BWGVillagerProfessions.FORAGER.get(), toIntMap(ImmutableMap.of( - 1, ImmutableList.of( - createEmeraldForItemsOffer(Items.RED_MUSHROOM, 10, 12, 2), - createEmeraldForItemsOffer(Items.BROWN_MUSHROOM, 10, 12, 2), - createEmeraldForItemsOffer(BWGBlocks.GREEN_MUSHROOM.get(), 10, 12, 2) - ), - 2, ImmutableList.of( - createEmeraldForItemsOffer(BWGBlocks.WOOD_BLEWIT.get(), 8, 12, 3), - createItemsForEmeraldsOffer(BWGItems.WHITE_PUFFBALL_CAP.get(), 4, 5, 4, 2, 0.05f) - ), - 3, ImmutableList.of( - createEmeraldForItemsOffer(BWGItems.WHITE_PUFFBALL_SPORES.get(), 4, 5, 4) - ), - 4, ImmutableList.of( - createItemsForEmeraldsOffer(BWGBlocks.WITCH_HAZEL_BRANCH.get(), 4, 9, 4, 3, 0.05f), - createItemsForEmeraldsOffer(BWGBlocks.WITCH_HAZEL_BLOSSOM.get(), 10, 1, 10, 3, 0.05f) - ), - 5, ImmutableList.of( - createItemsForEmeraldsOffer(BWGBlocks.SHELF_FUNGI.get(), 3, 9, 4, 4, 0.05f), - createEmeraldForItemsOffer(Items.SWEET_BERRIES, 16, 4, 2), - createEmeraldForItemsOffer(BWGItems.BLUEBERRIES.get(), 16, 4, 2) - ) - ))); - if (!BWGTradesConfig.INSTANCE.get().enableVanillaTradeAdditions()) return; + if (BWGTradesConfig.INSTANCE.villagerTrades.allowBWGForagerTrades.value()) + TRADES.put(BWGVillagerProfessions.FORAGER.get(), toIntMap(ImmutableMap.of( + 1, ImmutableList.of( + createEmeraldForItemsOffer(Items.RED_MUSHROOM, 10, 12, 2), + createEmeraldForItemsOffer(Items.BROWN_MUSHROOM, 10, 12, 2), + createEmeraldForItemsOffer(BWGBlocks.GREEN_MUSHROOM.get(), 10, 12, 2) + ), + 2, ImmutableList.of( + createEmeraldForItemsOffer(BWGBlocks.WOOD_BLEWIT.get(), 8, 12, 3), + createItemsForEmeraldsOffer(BWGItems.WHITE_PUFFBALL_CAP.get(), 4, 5, 4, 2, 0.05f) + ), + 3, ImmutableList.of( + createEmeraldForItemsOffer(BWGItems.WHITE_PUFFBALL_SPORES.get(), 4, 5, 4) + ), + 4, ImmutableList.of( + createItemsForEmeraldsOffer(BWGBlocks.WITCH_HAZEL_BRANCH.get(), 4, 9, 4, 3, 0.05f), + createItemsForEmeraldsOffer(BWGBlocks.WITCH_HAZEL_BLOSSOM.get(), 10, 1, 10, 3, 0.05f) + ), + 5, ImmutableList.of( + createItemsForEmeraldsOffer(BWGBlocks.SHELF_FUNGI.get(), 3, 9, 4, 4, 0.05f), + createEmeraldForItemsOffer(Items.SWEET_BERRIES, 16, 4, 2), + createEmeraldForItemsOffer(BWGItems.BLUEBERRIES.get(), 16, 4, 2) + ) + ))); + if (!BWGTradesConfig.INSTANCE.villagerTrades.enableBWGVanillaProfessionTradeAdditions.value()) return; TRADES.put(VillagerProfession.BUTCHER, toIntMap(ImmutableMap.of( 2, ImmutableList.of( createEmeraldForItemsOffer(BWGItems.BLUEBERRIES.get(), 10, 12, 2) @@ -80,6 +86,24 @@ public static void makeTrades() { ))); } + public static final Int2ObjectMap> WANDERING_TRADER_TRADES = new Int2ObjectOpenHashMap<>(); + + public static void makeWanderingTrades() { + List level1Items = new ArrayList<>(); + BWGWood.WOOD.stream().filter(item -> item.get() instanceof SaplingBlock).forEach(item -> + level1Items.add(createItemsForEmeraldsOffer(item.get(), 5, 1, 8, 1, 0.05f))); + BWGSandSet.getSandSets().forEach(bwgSandSet -> level1Items.add( + createItemsForEmeraldsOffer(bwgSandSet.getSand(), 1, 8, 8, 1, 0.05f))); + BWGBlocks.BLOCKS.stream().filter(block -> block.get() instanceof FlowerBlock).forEach(block -> + level1Items.add(createItemsForEmeraldsOffer(block.get(), 1, 1, 13, 1, 0.05f))); + level1Items.add(createItemsForEmeraldsOffer(BWGItems.TINY_LILY_PADS.get(), 1, 2, 5, 1, 0.05f)); + level1Items.add(createItemsForEmeraldsOffer(BWGItems.FLOWERING_TINY_LILY_PADS.get(), 1, 2, 5, 1, 0.05f)); + level1Items.add(createItemsForEmeraldsOffer(BWGBlocks.WEEPING_MILKCAP.get(), 1, 1, 12, 1, 0.05f)); + level1Items.add(createItemsForEmeraldsOffer(BWGBlocks.GREEN_MUSHROOM.get(), 1, 1, 12, 1, 0.05f)); + level1Items.add(createItemsForEmeraldsOffer(BWGBlocks.WOOD_BLEWIT.get(), 1, 1, 12, 1, 0.05f)); + WANDERING_TRADER_TRADES.put(1, level1Items); + } + private static MerchantOffer createEmeraldForItemsOffer(ItemLike item, int cost, int maxUses, int villagerXp) { return new MerchantOffer(new ItemStack(item, cost), new ItemStack(Items.EMERALD), maxUses, villagerXp, 0.05F); } diff --git a/Fabric/src/main/java/net/potionstudios/biomeswevegone/fabric/VanillaCompatFabric.java b/Fabric/src/main/java/net/potionstudios/biomeswevegone/fabric/VanillaCompatFabric.java index 93bea3013..fe01dfde8 100644 --- a/Fabric/src/main/java/net/potionstudios/biomeswevegone/fabric/VanillaCompatFabric.java +++ b/Fabric/src/main/java/net/potionstudios/biomeswevegone/fabric/VanillaCompatFabric.java @@ -33,7 +33,11 @@ public static void init() { ToolInteractions.registerTillables((block, pair) -> TillableBlockRegistry.register(block, pair.getFirst(), pair.getSecond())); registerBiomeModifiers(); registerLootModifiers(); - registerTrades(); + if (!BWGTradesConfig.INSTANCE.trades.disableTrades.value()) { + registerTrades(); + if (BWGTradesConfig.INSTANCE.wanderingTraderTrades.enableBWGItemsTrades.value()) + registerWanderingTrades(); + } } private static void registerFuels() { @@ -59,8 +63,8 @@ private static void registerLootModifiers() { } private static void registerTrades() { - if (!BWGTradesConfig.INSTANCE.get().enableTrades()) return; BWGVillagerTrades.makeTrades(); + if (BWGVillagerTrades.TRADES.isEmpty()) return; BWGVillagerTrades.TRADES.forEach((villagerProfession, offersMap) -> offersMap.forEach((level, offers) -> TradeOfferHelper.registerVillagerOffers(villagerProfession, level, factory -> { @@ -69,4 +73,14 @@ private static void registerTrades() { ) ); } + + private static void registerWanderingTrades() { + if (!BWGTradesConfig.INSTANCE.wanderingTraderTrades.enableBWGItemsTrades.value()) return; + BWGVillagerTrades.makeWanderingTrades(); + BWGVillagerTrades.WANDERING_TRADER_TRADES.forEach((level, offers) -> + TradeOfferHelper.registerWanderingTraderOffers(level, factory -> { + for (MerchantOffer offer : offers) factory.add((trader, random) -> offer); + }) + ); + } } diff --git a/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/BiomesWeveGoneForge.java b/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/BiomesWeveGoneForge.java index af7ae3eae..2746d64e5 100644 --- a/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/BiomesWeveGoneForge.java +++ b/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/BiomesWeveGoneForge.java @@ -66,6 +66,7 @@ private void onInitialize(final FMLCommonSetupEvent event) { private void onPostInitialize(final FMLLoadCompleteEvent event) { event.enqueueWork(BiomesWeveGone::postInit); BWGVillagerTrades.makeTrades(); + BWGVillagerTrades.makeWanderingTrades(); } /** diff --git a/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/VanillaCompatForge.java b/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/VanillaCompatForge.java index e1f5d76df..ef1afa05c 100644 --- a/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/VanillaCompatForge.java +++ b/Forge/src/main/java/net/potionstudios/biomeswevegone/forge/VanillaCompatForge.java @@ -15,6 +15,7 @@ import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent; import net.minecraftforge.event.level.BlockEvent; import net.minecraftforge.event.village.VillagerTradesEvent; +import net.minecraftforge.event.village.WandererTradesEvent; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.IEventBus; import net.potionstudios.biomeswevegone.util.BoneMealHandler; @@ -47,10 +48,18 @@ public static void init() { public static void registerVanillaCompatEvents(IEventBus bus) { bus.addListener(VanillaCompatForge::registerTillables); bus.addListener(VanillaCompatForge::registerFuels); - if (BWGTradesConfig.INSTANCE.get().enableTrades()) bus.addListener(VanillaCompatForge::onVillagerTrade); + if (!BWGTradesConfig.INSTANCE.trades.disableTrades.value()) { + bus.addListener(VanillaCompatForge::onVillagerTrade); + if (BWGTradesConfig.INSTANCE.wanderingTraderTrades.enableBWGItemsTrades.value()) + bus.addListener(VanillaCompatForge::onWanderingTrade); + } bus.addListener(VanillaCompatForge::onBoneMealUse); } + /** + * Register tillable blocks. + * @see BlockEvent.BlockToolModificationEvent + */ private static void registerTillables(final BlockEvent.BlockToolModificationEvent event) { if (event.getToolAction() == ToolActions.HOE_TILL && event.getLevel().getBlockState(event.getPos().above()).isAir()) { BlockState state = event.getState(); @@ -87,6 +96,16 @@ private static void onVillagerTrade(final VillagerTradesEvent event) { } } + /** + * Register wandering trader trades. + * @see WandererTradesEvent + */ + private static void onWanderingTrade(final WandererTradesEvent event) { + BWGVillagerTrades.WANDERING_TRADER_TRADES.forEach((level, offers) -> { + for (MerchantOffer offer : offers) event.getGenericTrades().add((trader, random) -> offer); + }); + } + /** * Handle bone meal use. * @see BonemealEvent