#Simulating Fishing Loot (1.21.5)

1 messages · Page 1 of 1 (latest)

magic musk
#

I am trying to simulate the fishing loot, but I can't seem to access the loot table. This is what I currently have:

LootWorldContext lootWorldContext = new LootWorldContext(((ServerWorld) player.getWorld()).toServerWorld(),
  null, null, player.getLuck());

  List<ItemStack> loot = LootTable.EMPTY.generateLoot(lootWorldContext);

  for (ItemStack stack : loot) {
    player.giveItemStack(stack);
  }

I know LootTables.FISHING_GAMEPLAY exists but it returns a RegistryKey<LootTable>

obsidian dagger
#

just check how /loot gives players loot

magic musk
#
private static int executeFish(CommandContext<ServerCommandSource> context, RegistryEntry<LootTable> lootTable, BlockPos pos, ItemStack stack, Target constructor) throws CommandSyntaxException {
        ServerCommandSource serverCommandSource = (ServerCommandSource)context.getSource();
        LootWorldContext lootWorldContext = (new LootWorldContext.Builder(serverCommandSource.getWorld())).add(LootContextParameters.ORIGIN, Vec3d.ofCenter(pos)).add(LootContextParameters.TOOL, stack).addOptional(LootContextParameters.THIS_ENTITY, serverCommandSource.getEntity()).build(LootContextTypes.FISHING);
        return getFeedbackMessageSingle(context, lootTable, lootWorldContext, constructor);
    }
#

that just seems to make a better lootWorldContext, but maybe thats all I need

#

unless I'm in the wrong spot

magic musk
#

This is what I have now:

LootTable lootTable = server.getReloadableRegistries().getLootTable(LootTables.FISHING_GAMEPLAY);
LootWorldContext lootWorldContext = (new LootWorldContext.Builder(((ServerWorld) player.getWorld()).toServerWorld()))
  .add(LootContextParameters.ORIGIN, Vec3d.ofCenter(pos))
  .add(LootContextParameters.TOOL, player.getMainHandStack())
  .add(LootContextParameters.THIS_ENTITY, player)
  .build(LootContextTypes.FISHING);

List<ItemStack> loot = lootTable.generateLoot(lootWorldContext);

for (ItemStack stack : loot) {
  player.giveItemStack(stack);
}

Working but no treasure, even with thousands of tries