Woot

Woot

24M Downloads

[1.9] New loot table system stopping FakePlayer drops

Ipsis opened this issue ยท 4 comments

commented

With the move to the loot tables in 1.9, some of the mob drops are no longer happening with a FakePlayer - or I've not coded it correctly.

There does seem to be a "condition": "killed_by_player" which may be part of the issue.

It is set for:

blaze - blaze rods
spider - spider eye
zombie - iron_ingot, carrot, potato
etc

So this needs some investigation.

commented

So with some quick debugging:

The getKillerPlayer method of LootContext is returning null for a FakePlayer.
EntityLivingBase.onDeath
this.getAttackingEntity() = null

commented

In 1.8.9:

OnDeath just called dropFewItems, which in the case of EntityBlaze just added blaze_rod if rng said yes.

In 1.9.0 we are now using the loot tables:

OnDeath now calls EntityLiving.dropLoot which uses the loot tables.
onDeath->dropLoot->generateLootForPools->generateLoot->testAllConditions.
It is testAllConditions that processes the "killed_by_player", however the player is null for the FakePlayer.

KilledByPlayer->testCondition. context.getKillerPlayer = null

So I might have to put a workaround in for vanilla, to fake generate these extra items, until I can work out how the loot tables are supposed to be processed with the FakePlayer.

commented

So the answer is that I'm not hitting the entity first before killing it. If I attack the entity with the fake player then the attackingPlayer would be set and the loot would be dropped. So I can either call atttackEntityFrom with an amount of 0 or just directly set the attackingPlayer value.

commented

The attackingPlayer field is protected, so with a little access transformer magic I can set that value to the fakePlayer and the blaze now drops blaze rods. Need to see if there is a better way of doing this before going with the access transformer method.