@@ -35,21 +35,32 @@ public abstract class LootMixin extends LockableContainerBlockEntity {
35
35
36
36
@ Shadow protected abstract DefaultedList <ItemStack > getInvStackList ();
37
37
38
+ @ Shadow protected long lootTableSeed ;
39
+
40
+ private final boolean isChest ;
41
+
38
42
protected LootMixin (BlockEntityType <?> blockEntityType , BlockPos blockPos , BlockState blockState ) {
39
43
super (blockEntityType , blockPos , blockState );
44
+ this .isChest = blockEntityType == BlockEntityType .CHEST ;
40
45
}
41
46
42
47
43
48
@ Inject (method = "checkLootInteraction" , at = @ At ("HEAD" ))
44
49
private void loot (PlayerEntity player , CallbackInfo ci )
45
50
{
46
- if (this .lootTableId != null && this .world .getServer () != null )
51
+ if (this .isChest && this . lootTableId != null && this .world .getServer () != null )
47
52
{
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
+ }
49
60
for (int i = 0 ; i < Integer .parseInt (ConfigUtils .config .getOrDefault ("max_hats_per_chest" ,"3" )); i ++) {
50
61
if (random .nextInt (Integer .parseInt (ConfigUtils .config .getOrDefault ("no_hat_per_roll" ,"3" )))==0 )
51
62
{
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 ()))));
53
64
}
54
65
}
55
66
0 commit comments