Search in sources :

Example 1 with IPlacementHelper

use of com.simibubi.create.foundation.utility.placement.IPlacementHelper in project Create by Creators-of-Create.

the class GantryShaftBlock method use.

@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult ray) {
    ItemStack heldItem = player.getItemInHand(hand);
    IPlacementHelper placementHelper = PlacementHelpers.get(placementHelperId);
    if (!placementHelper.matchesItem(heldItem))
        return InteractionResult.PASS;
    return placementHelper.getOffset(player, world, state, pos, ray).placeInWorld(world, ((BlockItem) heldItem.getItem()), player, hand, ray);
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) BlockItem(net.minecraft.world.item.BlockItem) IPlacementHelper(com.simibubi.create.foundation.utility.placement.IPlacementHelper)

Example 2 with IPlacementHelper

use of com.simibubi.create.foundation.utility.placement.IPlacementHelper in project Create by Creators-of-Create.

the class SpeedControllerBlock method use.

@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult ray) {
    ItemStack heldItem = player.getItemInHand(hand);
    IPlacementHelper helper = PlacementHelpers.get(placementHelperId);
    if (helper.matchesItem(heldItem))
        return helper.getOffset(player, world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
    return InteractionResult.PASS;
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) BlockItem(net.minecraft.world.item.BlockItem) IPlacementHelper(com.simibubi.create.foundation.utility.placement.IPlacementHelper)

Example 3 with IPlacementHelper

use of com.simibubi.create.foundation.utility.placement.IPlacementHelper in project Create by Creators-of-Create.

the class ShaftBlock method use.

@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult ray) {
    if (player.isShiftKeyDown() || !player.mayBuild())
        return InteractionResult.PASS;
    ItemStack heldItem = player.getItemInHand(hand);
    for (EncasedShaftBlock encasedShaft : new EncasedShaftBlock[] { AllBlocks.ANDESITE_ENCASED_SHAFT.get(), AllBlocks.BRASS_ENCASED_SHAFT.get() }) {
        if (!encasedShaft.getCasing().isIn(heldItem))
            continue;
        if (world.isClientSide)
            return InteractionResult.SUCCESS;
        AllTriggers.triggerFor(AllTriggers.CASING_SHAFT, player);
        KineticTileEntity.switchToBlockState(world, pos, encasedShaft.defaultBlockState().setValue(AXIS, state.getValue(AXIS)));
        return InteractionResult.SUCCESS;
    }
    IPlacementHelper helper = PlacementHelpers.get(placementHelperId);
    if (helper.matchesItem(heldItem))
        return helper.getOffset(player, world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
    return InteractionResult.PASS;
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) EncasedShaftBlock(com.simibubi.create.content.contraptions.relays.encased.EncasedShaftBlock) BlockItem(net.minecraft.world.item.BlockItem) IPlacementHelper(com.simibubi.create.foundation.utility.placement.IPlacementHelper)

Example 4 with IPlacementHelper

use of com.simibubi.create.foundation.utility.placement.IPlacementHelper in project Create by Creators-of-Create.

the class PistonExtensionPoleBlock method use.

@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult ray) {
    ItemStack heldItem = player.getItemInHand(hand);
    IPlacementHelper placementHelper = PlacementHelpers.get(placementHelperId);
    if (placementHelper.matchesItem(heldItem) && !player.isShiftKeyDown())
        return placementHelper.getOffset(player, world, state, pos, ray).placeInWorld(world, (BlockItem) heldItem.getItem(), player, hand, ray);
    return InteractionResult.PASS;
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) BlockItem(net.minecraft.world.item.BlockItem) IPlacementHelper(com.simibubi.create.foundation.utility.placement.IPlacementHelper)

Example 5 with IPlacementHelper

use of com.simibubi.create.foundation.utility.placement.IPlacementHelper in project Create by Creators-of-Create.

the class CogwheelBlockItem method onItemUseFirst.

@Override
public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
    Level world = context.getLevel();
    BlockPos pos = context.getClickedPos();
    BlockState state = world.getBlockState(pos);
    IPlacementHelper helper = PlacementHelpers.get(placementHelperId);
    Player player = context.getPlayer();
    BlockHitResult ray = new BlockHitResult(context.getClickLocation(), context.getClickedFace(), pos, true);
    if (helper.matchesState(state) && player != null && !player.isShiftKeyDown()) {
        return helper.getOffset(player, world, state, pos, ray).placeInWorld(world, this, player, context.getHand(), ray);
    }
    if (integratedCogHelperId != -1) {
        helper = PlacementHelpers.get(integratedCogHelperId);
        if (helper.matchesState(state) && player != null && !player.isShiftKeyDown()) {
            return helper.getOffset(player, world, state, pos, ray).placeInWorld(world, this, player, context.getHand(), ray);
        }
    }
    return super.onItemUseFirst(stack, context);
}
Also used : Player(net.minecraft.world.entity.player.Player) BlockState(net.minecraft.world.level.block.state.BlockState) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) IPlacementHelper(com.simibubi.create.foundation.utility.placement.IPlacementHelper)

Aggregations

IPlacementHelper (com.simibubi.create.foundation.utility.placement.IPlacementHelper)6 BlockItem (net.minecraft.world.item.BlockItem)5 ItemStack (net.minecraft.world.item.ItemStack)5 EncasedShaftBlock (com.simibubi.create.content.contraptions.relays.encased.EncasedShaftBlock)1 BlockPos (net.minecraft.core.BlockPos)1 Player (net.minecraft.world.entity.player.Player)1 DyeColor (net.minecraft.world.item.DyeColor)1 ShearsItem (net.minecraft.world.item.ShearsItem)1 Level (net.minecraft.world.level.Level)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 BlockHitResult (net.minecraft.world.phys.BlockHitResult)1