Jump to content

[1.6.4] Changing the chance of a custom villager trade


Da9L

Recommended Posts

Hello.

 

First of all i want to say that this is my entry project into modding with Forge, so my experience is low. However it has been a good experience so far.

 

So just to try it out, i began creating a very simple mod that adds custom trades to villagers. I wanted them to be able to trade emeralds for enchanted books at a higher rate.

 

So far it works well. I have two classes: My main class, and a TradeHandler. Besides loading configs my main class only has this:

 

VillagerRegistry.instance().registerVillageTradeHandler(1, new TradeHandler());
VillagerRegistry.instance().registerVillageTradeHandler(2, new TradeHandler());
VillagerRegistry.instance().registerVillageTradeHandler(3, new TradeHandler());
VillagerRegistry.instance().registerVillageTradeHandler(4, new TradeHandler());

 

My Trade handler looks like this:

 

public class TradeHandler implements IVillageTradeHandler{

@Override
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random)
{
	Random rand = new Random();	
	int Price = 64;

	Enchantment enchantment = Enchantment.enchantmentsBookList[random.nextInt(Enchantment.enchantmentsBookList.length)];
	//Enchantment enchantment = Enchantment.enchantmentsBookList[15];
        ItemStack enchantedBook = new ItemStack(Item.enchantedBook, 1);
        int lvl = MathHelper.getRandomIntegerInRange(rand, enchantment.getMinLevel(), enchantment.getMaxLevel());
        enchantedBook.addEnchantment(enchantment, lvl);
        switch (lvl) {
        	case 1 : Price = Main.lvl1Price;
        			 break;
        	case 2 : Price = Main.lvl2Price;
		 		 break;
        	case 3 : Price = Main.lvl3Price;
		 		 break;
        	case 4 : Price = Main.lvl4Price;
        			 break;
        	case 5 : Price = Main.lvl5Price;
		 		 break;
        }
        
        final String[] highCostBooks = convertStringToArraystring(Main.highPriceEnchantments);
        if(stringContainsItemFromList(enchantment.getTranslatedName(lvl), highCostBooks))
        {
        	Price = Main.highPriceEnchantmentsPrice;
        }

        

	recipeList.add(new MerchantRecipe(new ItemStack(Item.emerald, Price, 0), enchantedBook));
}

public static boolean stringContainsItemFromList(String inputString, String[] items)
{
    for(int i =0; i < items.length; i++)
    {
        if(inputString.contains(items[i]))
        {
            return true;
        }
    }
    return false;
}

public static String[] convertStringToArraystring(String input)
{
	String[] split = input.split(",");
	return split;
}

}

 

My problem is that, on a vanilla minecraft installation my custom trades is shown like 50% of the times.. But on a modded installation where other mods also add trades, i only get a 5% chance of my trade showing on a villager. I want this to have a higher chance. So basicly ..

 

Is it possible to set a higher chance of a specifc trade to get shown ?

 

Thanks in advance !

Link to comment
Share on other sites

Could I ask for a clarification of your issue?

 

By "vanilla minecraft installation" do you mean "Forge modded without other mods installed", which would indicate the problem is that your villager trades are getting "crowded out" by villager trades added by other mods?

 

Exactly what i mean :-)

Link to comment
Share on other sites

Well, I don't know that there is a good way of accomplishing that without crowding other mods' trades in return. There are quite a few methods in the VillagerRegistry that your mod can use to fiddle with the trade manifests. You're probably interested in manipulateTradesForVillager, which would let you directly manipulate the MerchantRecipeList of a given villager, or manageVillagerTrades which is a callback you could use for dealing with them in aggregate.

 

If you want a guaranteed way of accessing your custom trades, would you be willing to consider a custom villager? I understand that this isn't in the original scope of your mod's functionality but I feel it would be a better solution (in terms of compatibility, which is the root of your problem here) than just budging other mods' trades to the side. There are handy methods in the VillagerRegistry for this too, including ones that set the skin and whatnot.

 

TL;DR - Poke through VillagerRegistry.class, the answers are therein!

 

EDIT: Also, 1.6.4?

Link to comment
Share on other sites

Well, I don't know that there is a good way of accomplishing that without crowding other mods' trades in return. There are quite a few methods in the VillagerRegistry that your mod can use to fiddle with the trade manifests. You're probably interested in manipulateTradesForVillager, which would let you directly manipulate the MerchantRecipeList of a given villager, or manageVillagerTrades which is a callback you could use for dealing with them in aggregate.

 

If you want a guaranteed way of accessing your custom trades, would you be willing to consider a custom villager? I understand that this isn't in the original scope of your mod's functionality but I feel it would be a better solution (in terms of compatibility, which is the root of your problem here) than just budging other mods' trades to the side. There are handy methods in the VillagerRegistry for this too, including ones that set the skin and whatnot.

 

TL;DR - Poke through VillagerRegistry.class, the answers are therein!

 

EDIT: Also, 1.6.4?

 

Ill take a look at that.. Oh and as for the 1.6.4.. I have no intention of releasing a 1.6.4 version.. I have a 1.7.10 version ready which is the one i want to release.. The 1.6.4 is for my self on a server that runs 1.6.4..

 

I dont want to release the 1.6.4 version because in my opinion, staying at older versions just slows the hole progress of upgrading down for everyone :-)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • so I deleted all of my worlds after upgrading from 1.19 to 1.20, and I also deleted the cherished world favorites file. I have the same mods when the game did start up before the maps deleting. but I added 'em back and the game is still not loading. plz help 🙏 I even allocated 12gB of memory and i did use optifine my mod list my log
    • Minecraft opened, but when I went to create a new world I got another error. https://pastebin.com/mmdNztmW
    • java.lang.RuntimeException: Could not execute entrypoint stage 'main' due to errors, provided by 'terrablender'!     at net.fabricmc.loader.impl.FabricLoaderImpl.lambda$invokeEntrypoints$2(FabricLoaderImpl.java:388) ~[fabric-loader-0.15.11.jar:?]     at net.fabricmc.loader.impl.util.ExceptionUtil.gatherExceptions(ExceptionUtil.java:33) ~[fabric-loader-0.15.11.jar:?]     at net.fabricmc.loader.impl.FabricLoaderImpl.invokeEntrypoints(FabricLoaderImpl.java:386) ~[fabric-loader-0.15.11.jar:?]     at net.fabricmc.loader.impl.game.minecraft.Hooks.startServer(Hooks.java:63) ~[fabric-loader-0.15.11.jar:?]     at net.minecraft.server.Main.main(Main.java:112) ~[server-intermediary.jar:?]     at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:470) ~[fabric-loader-0.15.11.jar:?]     at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74) ~[fabric-loader-0.15.11.jar:?]     at net.fabricmc.loader.impl.launch.knot.KnotServer.main(KnotServer.java:23) ~[fabric-loader-0.15.11.jar:?]     at net.fabricmc.loader.impl.launch.server.FabricServerLauncher.main(FabricServerLauncher.java:69) ~[fabric-loader-0.15.11.jar:?] Caused by: java.lang.NoSuchFieldError: Class me.lortseam.completeconfig.data.BooleanEntry does not have member field 'boolean checkbox'     at me.lortseam.completeconfig.data.BooleanEntry.<init>(BooleanEntry.java:25) ~[completeconfig-base-2.5.0-cd5950f26b406f27.jar:?]     at me.lortseam.completeconfig.data.Entry.create(Entry.java:42) ~[completeconfig-base-2.5.0-cd5950f26b406f27.jar:?]     at me.lortseam.completeconfig.data.EntrySet.lambda$resolve$1(EntrySet.java:31) ~[completeconfig-base-2.5.0-cd5950f26b406f27.jar:?]     at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:212) ~[?:?]     at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:194) ~[?:?]     at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024) ~[?:?]     at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:556) ~[?:?]     at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:546) ~[?:?]     at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[?:?]     at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[?:?]     at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:265) ~[?:?]     at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:611) ~[?:?]     at me.lortseam.completeconfig.data.EntrySet.resolve(EntrySet.java:32) ~[completeconfig-base-2.5.0-cd5950f26b406f27.jar:?]     at me.lortseam.completeconfig.data.Parent.resolveContainer(Parent.java:58) ~[completeconfig-base-2.5.0-cd5950f26b406f27.jar:?]     at me.lortseam.completeconfig.data.Parent.resolve(Parent.java:110) ~[completeconfig-base-2.5.0-cd5950f26b406f27.jar:?]     at me.lortseam.completeconfig.data.Config.lambda$new$0(Config.java:51) ~[completeconfig-base-2.5.0-cd5950f26b406f27.jar:?]     at me.lortseam.completeconfig.data.Config.deserialize(Config.java:94) ~[completeconfig-base-2.5.0-cd5950f26b406f27.jar:?]     at me.lortseam.completeconfig.data.Config.load(Config.java:121) ~[completeconfig-base-2.5.0-cd5950f26b406f27.jar:?]     at io.github.uhq_games.regions_unexplored.RegionsUnexplored.onTerraBlenderInitialized(RegionsUnexplored.java:70) ~[RegionsUnexploredFabric-0.5.31.20.1.jar:?]     at terrablender.core.TerraBlenderFabric.lambda$onInitialize$0(TerraBlenderFabric.java:40) ~[TerraBlender-fabric-1.20.1-3.0.1.7.jar:?]     at java.util.ArrayList.forEach(ArrayList.java:1597) ~[?:?]     at terrablender.core.TerraBlenderFabric.onInitialize(TerraBlenderFabric.java:38) ~[TerraBlender-fabric-1.20.1-3.0.1.7.jar:?]     at net.fabricmc.loader.impl.FabricLoaderImpl.invokeEntrypoints(FabricLoaderImpl.java:384) ~[fabric-loader-0.15.11.jar:?]  
    • Hi, I have the oficial launcher using the version 1.21, and forge 51.0.13, as soon as I start the installation the games crashes and gives me "exit code: 1", I haven't put any mods yet in the folder. Its the second time that uninstall and install everything and nothing works, checket my graphics and they are updated. https://pastebin.com/STPgEiVs   thanks!
    • Ty very much it worked
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.