Skip to content

Commit

Permalink
return false in player canTakeItem for IFactionExclusiveItems
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Jun 2, 2024
1 parent a25de01 commit 15be8c1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/de/teamlapen/vampirism/mixin/MixinPlayerEntity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos pBedPos);

@Shadow public abstract void startAutoSpinAttack(int pAttackTicks);

@Unique
private final VampirismPlayerAttributes vampirismPlayerAttributes = new VampirismPlayerAttributes();

Expand Down Expand Up @@ -54,4 +66,14 @@ private Predicate<ItemStack> getAllSupport(Predicate<ItemStack> original, ItemSt
}
return original;
}

@Inject(method = "canTakeItem", at = @At("HEAD"), cancellable = true)
private void canTakeItem(ItemStack stack, CallbackInfoReturnable<Boolean> cir) {
if (stack.getItem() instanceof IFactionExclusiveItem item) {
IFaction<?> exclusiveFaction = item.getExclusiveFaction(stack);
if (exclusiveFaction != null && exclusiveFaction != this.vampirismPlayerAttributes.faction) {
cir.setReturnValue(false);
}
}
}
}

0 comments on commit 15be8c1

Please sign in to comment.