Skip to content

Commit

Permalink
Add the spread container loot rule type
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored and Patbox committed Dec 28, 2024
1 parent 2d1831c commit ba8769b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public final class GameRuleType {
public static final GameRuleType STOP_SPECTATING_ENTITY = GameRuleType.create();
public static final GameRuleType PLAYER_PROJECTILE_KNOCKBACK = GameRuleType.create();
public static final GameRuleType TRIDENTS_LOYAL_IN_VOID = GameRuleType.create();
public static final GameRuleType SPREAD_CONTAINER_LOOT = GameRuleType.create();
public static final GameRuleType MODIFY_INVENTORY = GameRuleType.create();
public static final GameRuleType MODIFY_ARMOR = GameRuleType.create();
public static final GameRuleType SWAP_OFFHAND = GameRuleType.create().enforces(PlayerSwapWithOffhandEvent.EVENT, result -> (player) -> result);
Expand Down
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;
}
}
1 change: 1 addition & 0 deletions src/main/resources/plasmid.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"game.portal.SignBlockEntityMixin",
"game.rule.EquippableComponentMixin",
"game.rule.HungerManagerMixin",
"game.rule.LootTableMixin",
"game.rule.PlayerEntityMixin",
"game.rule.ServerPlayerEntityMixin",
"game.rule.ServerPlayNetworkHandlerMixin",
Expand Down

0 comments on commit ba8769b

Please sign in to comment.