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

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A onUseOnBlock(ItemUsageContext,CallbackInfoReturnable) 0 6 2
1
package de.pewpewproject.lasertag.mixin;
2
3
import de.pewpewproject.lasertag.item.Items;
4
import net.minecraft.item.ItemStack;
5
import net.minecraft.item.ItemUsageContext;
6
import net.minecraft.util.ActionResult;
7
import org.spongepowered.asm.mixin.Mixin;
8
import org.spongepowered.asm.mixin.injection.At;
9
import org.spongepowered.asm.mixin.injection.Inject;
10
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
11
12
/**
13
 * Mixin into the ItemStack.class to stop the player from placing the flag
14
 *
15
 * @author Étienne Muser
16
 */
17
@Mixin(ItemStack.class)
18
public abstract class ItemStackMixin {
19
20
    /**
21
     * Inject into the useOnBlock() which is called when the player tries to place an item stack
22
     *
23
     * @param context
24
     * @param cir
25
     */
26
    @Inject(method = "useOnBlock(Lnet/minecraft/item/ItemUsageContext;)Lnet/minecraft/util/ActionResult;", at = @At("HEAD"), cancellable = true)
27
    private void onUseOnBlock(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir) {
28
29
        // If this stack is of lasertag flag
30
        if (((ItemStack)(Object)this).isOf(Items.LASERTAG_FLAG)) {
31
            cir.setReturnValue(ActionResult.PASS);
32
        }
33
    }
34
}
35