From 15be8c108760187cd20e01b2632cb40babc9ad3a Mon Sep 17 00:00:00 2001 From: cheaterpaul Date: Sun, 2 Jun 2024 15:41:34 +0200 Subject: [PATCH] return false in player canTakeItem for IFactionExclusiveItems --- .../vampirism/mixin/MixinPlayerEntity.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/de/teamlapen/vampirism/mixin/MixinPlayerEntity.java b/src/main/java/de/teamlapen/vampirism/mixin/MixinPlayerEntity.java index 01662ad87..d23ed9e4a 100644 --- a/src/main/java/de/teamlapen/vampirism/mixin/MixinPlayerEntity.java +++ b/src/main/java/de/teamlapen/vampirism/mixin/MixinPlayerEntity.java @@ -1,10 +1,15 @@ package de.teamlapen.vampirism.mixin; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.mojang.datafixers.util.Either; +import de.teamlapen.vampirism.api.entity.factions.IFaction; +import de.teamlapen.vampirism.api.items.IFactionExclusiveItem; import de.teamlapen.vampirism.api.items.IVampirismCrossbow; import de.teamlapen.vampirism.entity.player.IVampirismPlayer; import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; import de.teamlapen.vampirism.util.MixinHooks; +import net.minecraft.core.BlockPos; +import net.minecraft.util.Unit; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -13,14 +18,21 @@ import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.function.Predicate; @Mixin(Player.class) public abstract class MixinPlayerEntity extends LivingEntity implements IVampirismPlayer { + @Shadow public abstract Either startSleepInBed(BlockPos pBedPos); + + @Shadow public abstract void startAutoSpinAttack(int pAttackTicks); + @Unique private final VampirismPlayerAttributes vampirismPlayerAttributes = new VampirismPlayerAttributes(); @@ -54,4 +66,14 @@ private Predicate getAllSupport(Predicate original, ItemSt } return original; } + + @Inject(method = "canTakeItem", at = @At("HEAD"), cancellable = true) + private void canTakeItem(ItemStack stack, CallbackInfoReturnable cir) { + if (stack.getItem() instanceof IFactionExclusiveItem item) { + IFaction exclusiveFaction = item.getExclusiveFaction(stack); + if (exclusiveFaction != null && exclusiveFaction != this.vampirismPlayerAttributes.faction) { + cir.setReturnValue(false); + } + } + } }