-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the spread container loot rule type
- Loading branch information
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/xyz/nucleoid/plasmid/mixin/game/rule/LootTableMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package xyz.nucleoid.plasmid.mixin.game.rule; | ||
|
||
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; | ||
import com.llamalad7.mixinextras.sugar.Local; | ||
import it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.loot.LootTable; | ||
import net.minecraft.loot.context.LootContext; | ||
import net.minecraft.loot.context.LootContextParameters; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.util.math.random.Random; | ||
import xyz.nucleoid.plasmid.api.game.rule.GameRuleType; | ||
import xyz.nucleoid.plasmid.impl.game.manager.GameSpaceManagerImpl; | ||
import xyz.nucleoid.stimuli.event.EventResult; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(LootTable.class) | ||
public class LootTableMixin { | ||
@WrapWithCondition( | ||
method = "supplyInventory", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/loot/LootTable;shuffle(Lit/unimi/dsi/fastutil/objects/ObjectArrayList;ILnet/minecraft/util/math/random/Random;)V") | ||
) | ||
public boolean preventContainerLootShuffling(LootTable lootTable, ObjectArrayList<ItemStack> stacks, int freeSlots, Random random, @Local LootContext context) { | ||
var entity = context.get(LootContextParameters.THIS_ENTITY); | ||
var gameSpace = entity instanceof ServerPlayerEntity player ? GameSpaceManagerImpl.get().byPlayer(player) : GameSpaceManagerImpl.get().byWorld(context.getWorld()); | ||
|
||
if (gameSpace != null && gameSpace.getBehavior().testRule(GameRuleType.SPREAD_CONTAINER_LOOT) == EventResult.DENY) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters