Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mob#clearLootTable has no effect #11849

Open
NonSwag opened this issue Dec 28, 2024 · 5 comments
Open

Mob#clearLootTable has no effect #11849

NonSwag opened this issue Dec 28, 2024 · 5 comments
Labels
status: input wanted Looking for community feedback on this issue. version: 1.21.4

Comments

@NonSwag
Copy link
Contributor

NonSwag commented Dec 28, 2024

Expected behavior

Mob#clearLootTable (or setLootTable(null)) should prevent the mob from generating and dropping loot on death

Observed/Actual behavior

The mob still generates and drops its default loot

Steps/models to reproduce

  1. spawn a mob (pig for example)
  2. invoke the Mob#clearLootTable method (or set it to null)
  3. kill the entity

Plugin and Datapack List

irrelevant

Paper version

This server is running Paper version 1.21.4-61-main@e0abc5f (2024-12-28T14:03:42Z) (Implementing API version 1.21.4-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.4-34-d568e17 (MC: 1.21.4)

Other

No response

@Warriorrrr
Copy link
Member

This is due to the way Mob#getLootTable works in internals, it defaults to the entity type's default loot table if the Mob#lootTable field is an empty optional, which is what is set by the API.

Though what you're trying to do is already possible in the API using the EntityDeathEvent, just clear the getDrops there and the entity won't drop anything

@Warriorrrr Warriorrrr added status: input wanted Looking for community feedback on this issue. and removed status: needs triage labels Dec 28, 2024
@NonSwag
Copy link
Contributor Author

NonSwag commented Dec 28, 2024

Yeah, I just came to the same conclusion while reading through the code.
for now, I just pass an empty loot table instance because an event isn't a solution in my case (the loot table might get overridden later in the entity's lifecycle).

Judging from the docs, it sounds like setting the loot table to null will not generate loot on death of a mob.

Image

I feel like adding a resetLootTable method would be clearer for that, while also making it possible to have no loot table at all.
Also, getting the loot table after setting it to null, on an entity that has a loot table by default, will not return null which seems wrong.

@electronicboy
Copy link
Member

This is pretty much the joys of making loose promises in the API over existing implementations of behavior, if we want to enforce this API promise, most solutions here just introduce their own behavioral breakages, I think that the answer here is to just update the JDs to reflect the recentish changes and ensure that API exists for plugins to deal with whatever case they want

@Toseflo
Copy link

Toseflo commented Jan 4, 2025

In versions prior to 1.21.2, you could set the loot table to LootTables.EMPTY to create a mob that drops nothing. This loot table has been removed from Minecraft and Bukkit/Paper in 1.21.2.
You can still summon a mob that doesn't drop loot by specifying an invalid loot table like /summon sheep ~ ~ ~ {DeathLootTable:""}. You can't do this with Paper because, as far as I know, Paper only allows you to select from existing loot tables. So you would have to create a datapack containing an empty loot table, which could then be selected by your plugin to create such a mob.

It would be best if Paper could restore the lost LootTables.EMPTY functionality with a built-in datapack which provides an empty loot table. This way, you could also access it with commands like /summon sheep ~ ~ ~ {DeathLootTable:"paper:empty"} or something like that.

@Doc94
Copy link
Contributor

Doc94 commented Jan 5, 2025

How about just add this to the LootTable interface?

public static LootTable EMPTY = new LootTable() {

        @Override
        public @NotNull NamespacedKey getKey() {
            return new NamespacedKey("paper", "empty_loot_table");
        }

        @Override
        public @NotNull Collection<ItemStack> populateLoot(@Nullable final Random random, @NotNull final LootContext context) {
            return List.of();
        }

        @Override
        public void fillInventory(@NotNull final Inventory inventory, @Nullable final Random random, @NotNull final LootContext context) {

        }
    };

not fully like but not sure if just try to add in registry and empty work... NMS have a empty but its not registered then cannot be called in API unless mess with server side for make a thing like getEmptyLootTable for call this but the Craft implementation expect a loottable with key...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: input wanted Looking for community feedback on this issue. version: 1.21.4
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants