de.pewpewproject.lasertag.mixin.SlotMixin   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A onCanTakeItems(PlayerEntity,CallbackInfoReturnable) 0 8 1
1
package de.pewpewproject.lasertag.mixin;
2
3
import de.pewpewproject.lasertag.item.Items;
4
import net.minecraft.entity.player.PlayerEntity;
5
import net.minecraft.screen.slot.Slot;
6
import org.spongepowered.asm.mixin.Mixin;
7
import org.spongepowered.asm.mixin.injection.At;
8
import org.spongepowered.asm.mixin.injection.Inject;
9
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
10
11
/**
12
 * Mixin into the slot class to make lasertag vests effectively have curse of binding. The player can't take it off.
13
 *
14
 * @author Étienne Muser
15
 */
16
@Mixin(Slot.class)
17
public abstract class SlotMixin {
18
19
    @Inject(method = "canTakeItems(Lnet/minecraft/entity/player/PlayerEntity;)Z", at = @At("HEAD"), cancellable = true)
20
    private void onCanTakeItems(PlayerEntity playerEntity, CallbackInfoReturnable<Boolean> cir) {
21
22
        // Get the item stack of the slot
23
        var itemStack = ((Slot)(Object)this).getStack();
24
25
        // Player can always take it of if he is in creative mode. But otherwise can't take of the lasertag vest.
26
        cir.setReturnValue(playerEntity.isCreative() || !itemStack.isOf(Items.LASERTAG_VEST));
27
    }
28
}
29