Jump to content

[SOLVED] 1.19 Generate drop from fishing drop tables with luck of the sea.


Zacomat

Recommended Posts

Hi all!

So I have my wonderful, enchantiable fishing net up and running!!!
But when I generate the loot, almost always the drop table "minecraft:gameplay/fishing/fish" is choosen and almost never the drop table "minecraft:gameplay/fishing/treasure" is choosen even if I use luck of the sea 3.

This is the method in my NetBlockEntity where i get items to spawn:

	private List<ItemStack> fish() {
		ItemStack dummyStack = new ItemStack(Items.FISHING_ROD);
		dummyStack.setTag(orig);
		System.err.println("fish: dummyStack=" + dummyStack + " " + dummyStack.getTag());

		LootContext.Builder lootcontext$builder = new LootContext.Builder((ServerLevel) level)
				.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(worldPosition))
				.withParameter(LootContextParams.TOOL, dummyStack)
				.withRandom(level.random)
				.withLuck(fishingLuck);
		System.err.println("fish: fishingLuck=" + fishingLuck);
		System.err.println("fish: lootcontext$builder=" + lootcontext$builder);

		LootContext context = lootcontext$builder.create(LootContextParamSets.FISHING);
		System.err.println("fish: context.getLootingModifier()=" + context.getLootingModifier());
		System.err.println("fish: context.getLuck()=" + context.getLuck());


		LootTable loottable = level.getServer().getLootTables().get(BuiltInLootTables.FISHING);
		System.err.println("fish: loottable.getLootTableId()=" + loottable.getLootTableId());
		List<ItemStack> list = loottable.getRandomItems(context);
		return list;
	}

and this is the output:

fish: dummyStack=1 fishing_rod {Damage:0,Enchantments:[{id:"minecraft:luck_of_the_sea",lvl:3s}]}
fish: fishingLuck=3
fish: lootcontext$builder=net.minecraft.world.level.storage.loot.LootContext$Builder@642e2643
fish: context.getLootingModifier()=0
fish: context.getLuck()=3.0
fish: loottable.getLootTableId()=minecraft:gameplay/fishing
update: list=[1 pufferfish]

What is the value to pass to lootcontext$builder..withLuck()? It seems that the level of the enchantment (int fishingLuck in my case) is not working... The loot is very different from that obtained with fishing with an enchanted fishing rod.

Thx.

Edited by Zacomat
typing error
Link to comment
Share on other sites

The fishing loot table only uses the treasure loot table if the entity set in the loot context is a fishing hook and the hook is in "open water"

https://github.com/misode/mcmeta/blob/4efe0aaa9ee28ebe64b8c785d3382833ee7cdea1/data/minecraft/loot_tables/gameplay/fishing.json#L21

 

I suggest you write your own loot table that delegates to junk, treasure or fish using your own conditions/rules.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Ok i've added a dummy FishingHook too. When instanced the field private boolean openWater is true.  The dummyHook goes in the loot context as THIS_ENTITY. It seems to work! I made many tests. This is the code 

	private List<ItemStack> fish() {
		FishingHook dummyHook = new FishingHook(EntityType.FISHING_BOBBER, level);
		ItemStack dummyStack = new ItemStack(Items.FISHING_ROD);
		dummyStack.setTag(orig);
		System.err.println("fish: dummyStack=" + dummyStack + " " + dummyStack.getTag());

		LootContext.Builder lootcontext$builder = new LootContext.Builder((ServerLevel) level)
				.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(worldPosition))
				.withParameter(LootContextParams.TOOL, dummyStack)
				.withRandom(level.random)
				.withLuck(fishingLuck)
				.withParameter(LootContextParams.THIS_ENTITY, dummyHook);

		System.err.println("fish: fishingLuck=" + fishingLuck);
		System.err.println("fish: dummyHook.isOpenWaterFishing()=" + dummyHook.isOpenWaterFishing());

		FishingHookPredicate pr = FishingHookPredicate.inOpenWater(true);
		System.err.println("fish: pr matches? " + pr.matches(dummyHook, (ServerLevel) level, Vec3.atCenterOf(worldPosition)));

        LootContext context = lootcontext$builder.create(LootContextParamSets.FISHING);
		System.err.println("fish: context.getLootingModifier()=" + context.getLootingModifier());
		System.err.println("fish: context.getLuck()=" + context.getLuck());

      	LootTable loottable = level.getServer().getLootTables().get(BuiltInLootTables.FISHING);
		System.err.println("fish: loottable.getLootTableId()=" + loottable.getLootTableId());
		List<ItemStack> list = loottable.getRandomItems(context);
		return list;
	}

And ttis is the output:

fish: dummyStack=1 fishing_rod {Damage:0,Enchantments:[{id:"minecraft:luck_of_the_sea",lvl:3s}]}
fish: fishingLuck=3
fish: dummyHook.isOpenWaterFishing()=true
fish: pr matches? true
fish: context.getLootingModifier()=0
fish: context.getLuck()=3.0
fish: loottable.getLootTableId()=minecraft:gameplay/fishing
update: list=[1 cod]

The predicate is unused only for test... 

Thx very much!!!

Link to comment
Share on other sites

  • Zacomat changed the title to [SOLVED] 1.19 Generate drop from fishing drop tables with luck of the sea.

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.

Announcements



×
×
  • Create New...

Important Information

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