Skip to content

Commit 294c215

Browse files
authored
Merge pull request #28 from jlortiz0/master
Prevent NPE in LootMixin, this should have been fixed a long while ago, sorry
2 parents dbe95b8 + ffd3926 commit 294c215

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/main/java/gd/rf/acro/givemehats/mixin/LootMixin.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,32 @@ public abstract class LootMixin extends LockableContainerBlockEntity {
3535

3636
@Shadow protected abstract DefaultedList<ItemStack> getInvStackList();
3737

38+
@Shadow protected long lootTableSeed;
39+
40+
private final boolean isChest;
41+
3842
protected LootMixin(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
3943
super(blockEntityType, blockPos, blockState);
44+
this.isChest = blockEntityType == BlockEntityType.CHEST;
4045
}
4146

4247

4348
@Inject(method = "checkLootInteraction", at = @At("HEAD"))
4449
private void loot(PlayerEntity player, CallbackInfo ci)
4550
{
46-
if (this.lootTableId != null && this.world.getServer() != null)
51+
if (this.isChest && this.lootTableId != null && this.world.getServer() != null)
4752
{
48-
Random random = player.getRandom();
53+
Random random;
54+
if (player == null)
55+
{
56+
Random random = Random.create(this.lootTableSeed);
57+
} else {
58+
random = player.getRandom();
59+
}
4960
for (int i = 0; i < Integer.parseInt(ConfigUtils.config.getOrDefault("max_hats_per_chest","3")); i++) {
5061
if(random.nextInt(Integer.parseInt(ConfigUtils.config.getOrDefault("no_hat_per_roll","3")))==0)
5162
{
52-
this.getInvStackList().set(RandomUtils.nextInt(0,27),new ItemStack(GiveMeHats.LOADED_HATS.get(random.nextInt(GiveMeHats.LOADED_HATS.size()))));
63+
this.getInvStackList().set(RandomUtils.nextInt(0,this.size()),new ItemStack(GiveMeHats.LOADED_HATS.get(random.nextInt(GiveMeHats.LOADED_HATS.size()))));
5364
}
5465
}
5566

0 commit comments

Comments
 (0)