Search in sources :

Example 1 with IWrenchable

use of com.simibubi.create.content.contraptions.wrench.IWrenchable in project Materialis by RCXcrafter.

the class CreateWrenchingModifier method beforeBlockUse.

@Override
public ActionResultType beforeBlockUse(IModifierToolStack tool, int level, ItemUseContext context) {
    if (enabled && !tool.isBroken() && context.getPlayer() != null) {
        World world = context.getLevel();
        BlockPos pos = context.getClickedPos();
        BlockState state = context.getLevel().getBlockState(context.getClickedPos());
        Block block = state.getBlock();
        if (!(block instanceof IWrenchable)) {
            if (context.getPlayer().isSecondaryUseActive() && AllTags.AllBlockTags.WRENCH_PICKUP.matches(state)) {
                ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
                return onItemUseOnOther(world, pos, state, context);
            }
            return ActionResultType.PASS;
        }
        IWrenchable actor = (IWrenchable) block;
        ToolDamageUtil.damage(tool, 1, context.getPlayer(), context.getItemInHand());
        if (context.getPlayer().isSecondaryUseActive())
            return actor.onSneakWrenched(state, context);
        return actor.onWrenched(state, context);
    }
    return ActionResultType.PASS;
}
Also used : BlockState(net.minecraft.block.BlockState) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) IWrenchable(com.simibubi.create.content.contraptions.wrench.IWrenchable)

Aggregations

IWrenchable (com.simibubi.create.content.contraptions.wrench.IWrenchable)1 Block (net.minecraft.block.Block)1 BlockState (net.minecraft.block.BlockState)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 ServerWorld (net.minecraft.world.server.ServerWorld)1