use of net.minecraft.util.hit.BlockHitResult in project meteor-client by MeteorDevelopment.
the class AnchorAura method breakAnchor.
private void breakAnchor(BlockPos pos, FindItemResult anchor, FindItemResult glowStone) {
if (pos == null || mc.world.getBlockState(pos).getBlock() != Blocks.RESPAWN_ANCHOR)
return;
mc.player.setSneaking(false);
if (glowStone.isOffhand()) {
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.OFF_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
} else {
InvUtils.swap(glowStone.slot(), true);
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
}
if (anchor.isOffhand()) {
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.OFF_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
} else {
InvUtils.swap(anchor.slot(), true);
mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
}
InvUtils.swapBack();
}
use of net.minecraft.util.hit.BlockHitResult in project meteor-client by MeteorDevelopment.
the class CrystalAura method getPlaceInfo.
private BlockHitResult getPlaceInfo(BlockPos blockPos) {
((IVec3d) vec3d).set(mc.player.getX(), mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ());
for (Direction side : Direction.values()) {
((IVec3d) vec3dRayTraceEnd).set(blockPos.getX() + 0.5 + side.getVector().getX() * 0.5, blockPos.getY() + 0.5 + side.getVector().getY() * 0.5, blockPos.getZ() + 0.5 + side.getVector().getZ() * 0.5);
((IRaycastContext) raycastContext).set(vec3d, vec3dRayTraceEnd, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, mc.player);
BlockHitResult result = mc.world.raycast(raycastContext);
if (result != null && result.getType() == HitResult.Type.BLOCK && result.getBlockPos().equals(blockPos)) {
return result;
}
}
Direction side = blockPos.getY() > vec3d.y ? Direction.DOWN : Direction.UP;
return new BlockHitResult(vec3d, side, blockPos, false);
}
use of net.minecraft.util.hit.BlockHitResult in project meteor-client by MeteorDevelopment.
the class EChestFarmer method onTick.
@EventHandler
private void onTick(TickEvent.Pre event) {
// Finding target pos
if (target == null) {
if (mc.crosshairTarget == null || mc.crosshairTarget.getType() != HitResult.Type.BLOCK)
return;
BlockPos pos = ((BlockHitResult) mc.crosshairTarget).getBlockPos().up();
BlockState state = mc.world.getBlockState(pos);
if (state.getMaterial().isReplaceable() || state.getBlock() == Blocks.ENDER_CHEST) {
target = ((BlockHitResult) mc.crosshairTarget).getBlockPos().up();
} else
return;
}
// Disable if the block is too far away
if (PlayerUtils.distanceTo(target) > mc.interactionManager.getReachDistance()) {
error("Target block pos out of reach.");
target = null;
return;
}
// Toggle if obby amount reached
if (selfToggle.get() && InvUtils.find(Items.OBSIDIAN).count() - (ignoreExisting.get() ? startCount : 0) >= amount.get()) {
InvUtils.swapBack();
toggle();
return;
}
// Break existing echest at target pos
if (mc.world.getBlockState(target).getBlock() == Blocks.ENDER_CHEST) {
double bestScore = -1;
int bestSlot = -1;
for (int i = 0; i < 9; i++) {
ItemStack itemStack = mc.player.getInventory().getStack(i);
if (EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, itemStack) > 0)
continue;
double score = itemStack.getMiningSpeedMultiplier(Blocks.ENDER_CHEST.getDefaultState());
if (score > bestScore) {
bestScore = score;
bestSlot = i;
}
}
if (bestSlot == -1)
return;
InvUtils.swap(bestSlot, true);
BlockUtils.breakBlock(target, swingHand.get());
}
// Place echest if the target pos is empty
if (mc.world.getBlockState(target).getMaterial().isReplaceable()) {
FindItemResult echest = InvUtils.findInHotbar(Items.ENDER_CHEST);
if (!echest.found()) {
error("No Echests in hotbar, disabling");
toggle();
return;
}
BlockUtils.place(target, echest, true, 0, true);
}
}
use of net.minecraft.util.hit.BlockHitResult in project tweakermore by Fallen-Breath.
the class SignTextCopier method copySignText.
public static boolean copySignText(KeyAction action, IKeybind key) {
MinecraftClient mc = MinecraftClient.getInstance();
if (mc.world != null && mc.crosshairTarget != null && mc.crosshairTarget.getType() == HitResult.Type.BLOCK) {
BlockPos blockPos = ((BlockHitResult) mc.crosshairTarget).getBlockPos();
BlockState blockState = mc.world.getBlockState(blockPos);
if (blockState.getBlock() instanceof AbstractSignBlock) {
BlockEntity blockEntity = mc.world.getBlockEntity(blockPos);
if (blockEntity instanceof SignBlockEntity) {
String text = Joiner.on("\n").join(Arrays.stream(((SignBlockEntity) blockEntity).text).map(Text::getString).collect(Collectors.toList()));
text = StringUtils.strip(text);
if (!text.isEmpty()) {
mc.keyboard.setClipboard(text);
InfoUtils.printActionbarMessage("tweakermore.config.copySignTextToClipBoard.sign_copied", blockState.getBlock().getName());
} else {
InfoUtils.printActionbarMessage("tweakermore.config.copySignTextToClipBoard.empty_sign", blockState.getBlock().getName());
}
return true;
}
}
}
InfoUtils.printActionbarMessage("tweakermore.config.copySignTextToClipBoard.no_sign");
return false;
}
use of net.minecraft.util.hit.BlockHitResult 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);
}
}
}
}
Aggregations