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

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
eloc 9
dl 18
loc 18
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A onUse(BlockState,World,BlockPos,PlayerEntity,Hand,BlockHitResult,CallbackInfoReturnable) 15 15 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
package de.pewpewproject.lasertag.mixin;
2
3
import de.pewpewproject.lasertag.worldgen.chunkgen.ArenaChunkGenerator;
4
import net.minecraft.block.BedBlock;
5
import net.minecraft.block.BlockState;
6
import net.minecraft.entity.player.PlayerEntity;
7
import net.minecraft.util.ActionResult;
8
import net.minecraft.util.Hand;
9
import net.minecraft.util.hit.BlockHitResult;
10
import net.minecraft.util.math.BlockPos;
11
import net.minecraft.world.World;
12
import net.minecraft.world.dimension.DimensionOptions;
13
import org.spongepowered.asm.mixin.Mixin;
14
import org.spongepowered.asm.mixin.injection.At;
15
import org.spongepowered.asm.mixin.injection.Inject;
16
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
17
18
import java.util.Objects;
19
20
/**
21
 * Mixin into the BedBlock.class to disable the bed if it is in an arena world
22
 *
23
 * @author Étienne Muser
24
 */
25 View Code Duplication
@Mixin(BedBlock.class)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
26
public class BedBlockMixin {
27
28
    @Inject(method = "onUse(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;", at = @At("HEAD"), cancellable = true)
29
    private void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable<ActionResult> cir) {
30
31
        // If world is not server
32
        if (world.isClient) {
33
            return;
34
        }
35
36
        // If is not an arena world
37
        if (!(Objects.requireNonNull(Objects.requireNonNull(world.getServer()).getSaveProperties().getGeneratorOptions().getDimensions().get(DimensionOptions.OVERWORLD))
38
                .chunkGenerator instanceof ArenaChunkGenerator)) {
39
            return;
40
        }
41
42
        cir.setReturnValue(ActionResult.PASS);
43
    }
44
}
45