use of net.minecraft.item.ItemUsageContext in project Paradise-Lost by devs-immortal.
the class HoeItemMixin method useOnBlock.
@Inject(at = @At("HEAD"), method = "useOnBlock", cancellable = true)
public void useOnBlock(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir) {
World world = context.getWorld();
BlockPos blockPos = context.getBlockPos();
Map<Block, BlockState> AETHER_TILLED_BLOCKS = new HashMap<>();
AETHER_TILLED_BLOCKS.put(AetherBlocks.AETHER_GRASS_BLOCK, AetherBlocks.AETHER_FARMLAND.getDefaultState());
AETHER_TILLED_BLOCKS.put(AetherBlocks.AETHER_DIRT, AetherBlocks.AETHER_FARMLAND.getDefaultState());
if (context.getSide() != Direction.DOWN && world.getBlockState(blockPos.up()).isAir()) {
BlockState blockState = AETHER_TILLED_BLOCKS.get(world.getBlockState(blockPos).getBlock());
if (blockState != null) {
PlayerEntity playerEntity = context.getPlayer();
world.playSound(playerEntity, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
if (!world.isClient) {
world.setBlockState(blockPos, blockState, 11);
if (playerEntity != null)
context.getStack().damage(1, playerEntity, (p) -> p.sendToolBreakStatus(context.getHand()));
}
cir.setReturnValue(ActionResult.success(world.isClient));
}
}
}
use of net.minecraft.item.ItemUsageContext in project friends-and-foes by Faboslav.
the class CopperButtonBlock method onUse.
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ItemStack itemStack = player.getStackInHand(hand);
Item itemInHand = itemStack.getItem();
if (itemInHand instanceof AxeItem) {
ItemUsageContext itemUsageContext = new ItemUsageContext(player, hand, hit);
ActionResult itemInHandUsageResult = itemInHand.useOnBlock(itemUsageContext);
if (itemInHandUsageResult.isAccepted()) {
return itemInHandUsageResult;
}
}
return super.onUse(state, world, pos, player, hand, hit);
}
use of net.minecraft.item.ItemUsageContext in project JexClient by DustinRepo.
the class BlockPlacer method placeBlockWithoutInteractingBlock.
private static void placeBlockWithoutInteractingBlock(MinecraftClient minecraftClient, BlockHitResult hitResult) {
ClientPlayerEntity player = minecraftClient.player;
ItemStack itemStack = player.getStackInHand(Hand.MAIN_HAND);
minecraftClient.getNetworkHandler().sendPacket(new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, hitResult));
if (!itemStack.isEmpty() && !player.getItemCooldownManager().isCoolingDown(itemStack.getItem())) {
ItemUsageContext itemUsageContext = new ItemUsageContext(player, Hand.MAIN_HAND, hitResult);
itemStack.useOnBlock(itemUsageContext);
}
}
use of net.minecraft.item.ItemUsageContext in project Immersive-Weathering by AstralOrdana.
the class LeafPileBlockItem method use.
@Override
public TypedActionResult<ItemStack> use(World p_43441_, PlayerEntity p_43442_, Hand p_43443_) {
BlockHitResult blockhitresult = raycast(p_43441_, p_43442_, RaycastContext.FluidHandling.SOURCE_ONLY);
BlockHitResult blockhitresult1 = blockhitresult.withBlockPos(blockhitresult.getBlockPos().up());
ActionResult interactionresult = super.useOnBlock(new ItemUsageContext(p_43442_, p_43443_, blockhitresult1));
return new TypedActionResult<>(interactionresult, p_43442_.getStackInHand(p_43443_));
}
Aggregations