use of net.minecraft.item.ItemUsageContext in project wildmod by Osmiooo.
the class FrogSpawnItem method use.
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
BlockHitResult blockHitResult = FrogSpawnItem.raycast(world, user, RaycastContext.FluidHandling.SOURCE_ONLY);
BlockHitResult blockHitResult2 = blockHitResult.withBlockPos(blockHitResult.getBlockPos().up());
ActionResult actionResult = super.useOnBlock(new ItemUsageContext(user, hand, blockHitResult2));
return new TypedActionResult<ItemStack>(actionResult, user.getStackInHand(hand));
}
use of net.minecraft.item.ItemUsageContext in project tweakermore by Fallen-Breath.
the class PlacementTweaksMixin method tweakmAutoPickSchematicBlock.
@Inject(method = "tryPlaceBlock", at = @At("HEAD"), remap = false)
private static void tweakmAutoPickSchematicBlock(ClientPlayerInteractionManager controller, ClientPlayerEntity player, ClientWorld world, BlockPos posIn, Direction sideIn, Direction sideRotatedIn, float playerYaw, Vec3d hitVec, Hand hand, PositionUtils.HitPart hitPart, boolean isFirstClick, CallbackInfoReturnable<ActionResult> cir) {
MinecraftClient mc = MinecraftClient.getInstance();
if (mc.player != null) {
if (DataManager.getToolMode() != ToolMode.REBUILD && !Configs.Generic.EASY_PLACE_MODE.getBooleanValue()) {
if (TweakerMoreConfigs.TWEAKM_AUTO_PICK_SCHEMATIC_BLOCK.getBooleanValue() && EntityUtils.shouldPickBlock(mc.player)) {
BlockHitResult hitResult = new BlockHitResult(hitVec, sideIn, posIn, false);
ItemPlacementContext ctx = new ItemPlacementContext(new ItemUsageContext(player, hand, hitResult));
doSchematicWorldPickBlock(mc, ctx.getBlockPos(), hand);
}
}
}
}
use of net.minecraft.item.ItemUsageContext in project Paradise-Lost by devs-immortal.
the class AxeItemMixin 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();
BlockState blockState = world.getBlockState(blockPos);
Map<Block, Block> AETHER_STRIPPED_BLOCKS = new HashMap<>();
AETHER_STRIPPED_BLOCKS.put(AetherBlocks.CRYSTAL_LOG, AetherBlocks.STRIPPED_CRYSTAL_LOG);
AETHER_STRIPPED_BLOCKS.put(AetherBlocks.GOLDEN_OAK_LOG, AetherBlocks.STRIPPED_GOLDEN_OAK_LOG);
AETHER_STRIPPED_BLOCKS.put(AetherBlocks.SKYROOT_LOG, AetherBlocks.STRIPPED_SKYROOT_LOG);
AETHER_STRIPPED_BLOCKS.put(AetherBlocks.WISTERIA_LOG, AetherBlocks.STRIPPED_WISTERIA_LOG);
Block block = AETHER_STRIPPED_BLOCKS.get(blockState.getBlock());
if (block != null) {
PlayerEntity playerEntity = context.getPlayer();
world.playSound(playerEntity, blockPos, SoundEvents.ITEM_AXE_STRIP, SoundCategory.BLOCKS, 1.0F, 1.0F);
if (!world.isClient) {
world.setBlockState(blockPos, block.getDefaultState().with(PillarBlock.AXIS, blockState.get(PillarBlock.AXIS)), 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 Paradise-Lost by devs-immortal.
the class ShovelItemMixin 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();
BlockState blockState = world.getBlockState(blockPos);
Map<Block, BlockState> AETHER_PATH_STATES = new HashMap<>();
AETHER_PATH_STATES.put(AetherBlocks.AETHER_GRASS_BLOCK, AetherBlocks.AETHER_DIRT_PATH.getDefaultState());
AETHER_PATH_STATES.put(AetherBlocks.AETHER_DIRT, AetherBlocks.AETHER_DIRT_PATH.getDefaultState());
if (context.getSide() == Direction.DOWN) {
cir.setReturnValue(ActionResult.PASS);
} else {
PlayerEntity playerEntity = context.getPlayer();
BlockState blockState2 = AETHER_PATH_STATES.get(blockState.getBlock());
BlockState blockState3 = null;
if (blockState2 != null && world.getBlockState(blockPos.up()).isAir()) {
world.playSound(playerEntity, blockPos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
blockState3 = blockState2;
} else if (blockState.getBlock() instanceof CampfireBlock && blockState.get(CampfireBlock.LIT)) {
if (!world.isClient())
world.syncWorldEvent(null, 1009, blockPos, 0);
CampfireBlock.extinguish(world, blockPos, blockState);
blockState3 = blockState.with(CampfireBlock.LIT, false);
}
if (blockState3 != null) {
if (!world.isClient) {
world.setBlockState(blockPos, blockState3, 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 FastAsyncWorldEdit by IntellectualSites.
the class FabricWorld method useItem.
@Override
public boolean useItem(BlockVector3 position, BaseItem item, Direction face) {
ItemStack stack = FabricAdapter.adapt(new BaseItemStack(item.getType(), item.getNbtData(), 1));
ServerWorld world = (ServerWorld) getWorld();
final WorldEditFakePlayer fakePlayer;
try {
fakePlayer = fakePlayers.get(world);
} catch (ExecutionException ignored) {
return false;
}
fakePlayer.setStackInHand(Hand.MAIN_HAND, stack);
fakePlayer.setPositionAndAngles(position.getBlockX(), position.getBlockY(), position.getBlockZ(), (float) face.toVector().toYaw(), (float) face.toVector().toPitch());
final BlockPos blockPos = FabricAdapter.toBlockPos(position);
final BlockHitResult rayTraceResult = new BlockHitResult(FabricAdapter.toVec3(position), FabricAdapter.adapt(face), blockPos, false);
ItemUsageContext itemUseContext = new ItemUsageContext(fakePlayer, Hand.MAIN_HAND, rayTraceResult);
ActionResult used = stack.useOnBlock(itemUseContext);
if (used != ActionResult.SUCCESS) {
// try activating the block
if (getWorld().getBlockState(blockPos).activate(world, fakePlayer, Hand.MAIN_HAND, rayTraceResult)) {
used = ActionResult.SUCCESS;
} else {
used = stack.getItem().use(world, fakePlayer, Hand.MAIN_HAND).getResult();
}
}
return used == ActionResult.SUCCESS;
}
Aggregations