Skip to content

Commit

Permalink
Fix loot table NPE (#1286)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Mar 22, 2024
1 parent 84134c7 commit 841f2b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
public interface LootTableBridge {

void bridge$setCraftLootTable(CraftLootTable lootTable);

CraftLootTable bridge$getCraftLootTable();
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ public abstract class LootTableMixin implements LootTableBridge {
this.craftLootTable = lootTable;
}

@Override
public CraftLootTable bridge$getCraftLootTable() {
return this.craftLootTable;
}

@Eject(method = "fill", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/loot/LootTable;getRandomItems(Lnet/minecraft/world/level/storage/loot/LootContext;)Lit/unimi/dsi/fastutil/objects/ObjectArrayList;"))
private ObjectArrayList<ItemStack> arclight$nonPluginEvent(LootTable lootTable, LootContext context, CallbackInfo ci, Container inv) {
ObjectArrayList<ItemStack> list = this.getRandomItems(context);
if (!context.hasParam(LootContextParams.ORIGIN) && !context.hasParam(LootContextParams.THIS_ENTITY)) {
return list;
}
if (((LootTableBridge) this).bridge$getCraftLootTable() == null) {
return list;
}
LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, list, false);
if (event.isCancelled()) {
ci.cancel();
Expand All @@ -64,11 +72,13 @@ public void fillInventory(Container inv, LootParams lootparams, long i, boolean
LootContext context = (new LootContext.Builder(lootparams)).withOptionalRandomSeed(i).create(this.randomSequence);
ObjectArrayList<ItemStack> objectarraylist = this.getRandomItems(context);
RandomSource randomsource = context.getRandom();
LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, objectarraylist, plugin);
if (event.isCancelled()) {
return;
if (((LootTableBridge) this).bridge$getCraftLootTable() != null) {
LootGenerateEvent event = CraftEventFactory.callLootGenerateEvent(inv, (LootTable) (Object) this, context, objectarraylist, plugin);
if (event.isCancelled()) {
return;
}
objectarraylist = event.getLoot().stream().map(CraftItemStack::asNMSCopy).collect(ObjectArrayList.toList());
}
objectarraylist = event.getLoot().stream().map(CraftItemStack::asNMSCopy).collect(ObjectArrayList.toList());

List<Integer> list = this.getAvailableSlots(inv, randomsource);
this.shuffleAndSplitItems(objectarraylist, list.size(), randomsource);
Expand Down

0 comments on commit 841f2b3

Please sign in to comment.