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

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A onDropSelectedItem(boolean,CallbackInfoReturnable) 0 11 3
1
package de.pewpewproject.lasertag.mixin;
2
3
import de.pewpewproject.lasertag.item.Items;
4
import net.minecraft.entity.player.PlayerInventory;
5
import net.minecraft.item.ItemStack;
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 PlayerInventory.class to prevent the player from dropping his weapon.
13
 *
14
 * @author Étienne Muser
15
 */
16
@Mixin(PlayerInventory.class)
17
public abstract class PlayerInventoryMixin {
18
19
    @Inject(method = "dropSelectedItem(Z)Lnet/minecraft/item/ItemStack;", at = @At("HEAD"), cancellable = true)
20
    private void onDropSelectedItem(boolean entireStack, CallbackInfoReturnable<ItemStack> cir) {
21
        // Get the main hand stack
22
        var mainHandStack = ((PlayerInventory)(Object)this).getMainHandStack();
23
24
        // If is lasertag weapon
25
        if (mainHandStack.isOf(Items.LASERTAG_WEAPON) ||
26
            mainHandStack.isOf(Items.LASERTAG_FLAG)) {
27
28
            // Don't drop it
29
            cir.setReturnValue(ItemStack.EMPTY);
30
        }
31
    }
32
}
33