use of net.minecraft.util.hit.HitResult in project meteor-client by MeteorDevelopment.
the class ClickTP method onTick.
@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.player.isUsingItem())
return;
if (mc.options.useKey.isPressed()) {
HitResult hitResult = mc.player.raycast(maxDistance.get(), 1f / 20f, false);
if (hitResult.getType() == HitResult.Type.ENTITY && mc.player.interact(((EntityHitResult) hitResult).getEntity(), Hand.MAIN_HAND) != ActionResult.PASS)
return;
if (hitResult.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult) hitResult).getBlockPos();
Direction side = ((BlockHitResult) hitResult).getSide();
if (mc.world.getBlockState(pos).onUse(mc.world, mc.player, Hand.MAIN_HAND, (BlockHitResult) hitResult) != ActionResult.PASS)
return;
BlockState state = mc.world.getBlockState(pos);
VoxelShape shape = state.getCollisionShape(mc.world, pos);
if (shape.isEmpty())
shape = state.getOutlineShape(mc.world, pos);
double height = shape.isEmpty() ? 1 : shape.getMax(Direction.Axis.Y);
mc.player.setPosition(pos.getX() + 0.5 + side.getOffsetX(), pos.getY() + height, pos.getZ() + 0.5 + side.getOffsetZ());
}
}
}
use of net.minecraft.util.hit.HitResult in project MasaGadget by plusls.
the class MixinWorldRenderer method postRender.
@Inject(method = "render", at = @At(value = "RETURN"))
private void postRender(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) {
MinecraftClient mc = MinecraftClient.getInstance();
World world = WorldUtils.getBestWorld(mc);
if (world == null || mc.player == null) {
return;
}
Entity cameraEntity = world.getPlayerByUuid(mc.player.getUuid());
if (cameraEntity == null) {
cameraEntity = mc.player;
}
if (FeatureToggle.TWEAK_FREE_CAMERA.getBooleanValue()) {
cameraEntity = mc.getCameraEntity();
}
if (!FeatureToggle.TWEAK_INVENTORY_PREVIEW.getBooleanValue() || !Hotkeys.INVENTORY_PREVIEW.getKeybind().isKeybindHeld() || !Configs.Tweakeroo.INVENTORY_PREVIEW_SUPPORT_COMPARATOR.getBooleanValue() || cameraEntity == null) {
return;
}
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.multiplyPositionMatrix(matrices.peek().getPositionMatrix());
RenderSystem.applyModelViewMatrix();
// 开始渲染
HitResult trace = RayTraceUtils.getRayTraceFromEntity(world, cameraEntity, false);
if (trace.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult) trace).getBlockPos();
// 绕过线程检查
BlockEntity blockEntity = world.getWorldChunk(pos).getBlockEntity(pos);
if (blockEntity instanceof ComparatorBlockEntity) {
LiteralText literalText = new LiteralText(((ComparatorBlockEntity) blockEntity).getOutputSignal() + "");
literalText.formatted(Formatting.GREEN);
// literalText.formatted(Formatting.);
VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
// 不加 1.17 渲染会有问题
RenderSystem.disableDepthTest();
matrixStack.push();
matrixStack.translate(pos.getX() + 0.5 - camera.getPos().getX(), pos.getY() + 0.6 - camera.getPos().getY(), pos.getZ() + 0.5 - camera.getPos().getZ());
matrixStack.multiplyPositionMatrix(new Matrix4f(camera.getRotation()));
matrixStack.scale(-0.04F, -0.04F, -0.04F);
RenderSystem.applyModelViewMatrix();
Matrix4f lv = AffineTransformation.identity().getMatrix();
float xOffset = (float) (-mc.textRenderer.getWidth(literalText) / 2);
float g = mc.options.getTextBackgroundOpacity(0.25F);
int k = (int) (g * 255.0F) << 24;
mc.textRenderer.draw(literalText, xOffset, 0, 553648127, false, lv, immediate, true, k, 0xf00000);
immediate.draw();
mc.textRenderer.draw(literalText, xOffset, 0, -1, false, lv, immediate, true, 0, 0xf00000);
immediate.draw();
matrixStack.pop();
RenderSystem.applyModelViewMatrix();
RenderSystem.enableDepthTest();
}
}
// 结束渲染
matrixStack.pop();
RenderSystem.applyModelViewMatrix();
}
use of net.minecraft.util.hit.HitResult in project Biome-Makeover by Lemonszz.
the class BMBoatItem method use.
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack itemStack = user.getStackInHand(hand);
HitResult hitResult = Item.raycast(world, user, RaycastContext.FluidHandling.ANY);
if (hitResult.getType() == HitResult.Type.MISS) {
return TypedActionResult.pass(itemStack);
} else {
Vec3d vec3d = user.getRotationVec(1.0F);
List<Entity> list = world.getOtherEntities(user, user.getBoundingBox().stretch(vec3d.multiply(5.0D)).expand(1.0D), EntityPredicates.EXCEPT_SPECTATOR.and(Entity::collides));
if (!list.isEmpty()) {
Vec3d cameraPosVec = user.getCameraPosVec(1.0F);
for (Entity entity : list) {
Box box = entity.getBoundingBox().expand(entity.getTargetingMargin());
if (box.contains(cameraPosVec)) {
return TypedActionResult.pass(itemStack);
}
}
}
if (hitResult.getType() == HitResult.Type.BLOCK) {
BMBoatEntity boatEntity = createBoat(world, hitResult.getPos().x, hitResult.getPos().y, hitResult.getPos().z, user.yaw);
if (!world.isSpaceEmpty(boatEntity, boatEntity.getBoundingBox().expand(-0.1D))) {
return TypedActionResult.fail(itemStack);
} else {
if (!world.isClient) {
world.spawnEntity(boatEntity);
if (!user.abilities.creativeMode) {
itemStack.decrement(1);
}
}
user.incrementStat(Stats.USED.getOrCreateStat(this));
return TypedActionResult.success(itemStack);
}
} else {
return TypedActionResult.pass(itemStack);
}
}
}
use of net.minecraft.util.hit.HitResult in project Hypnotic-Client by Hypnotic-Development.
the class MiddleClickFriend method mouseClicked.
@EventTarget
public void mouseClicked(EventMouseButton event) {
if (event.getButton() == GLFW.GLFW_MOUSE_BUTTON_MIDDLE && event.getClickType() == EventMouseButton.ClickType.IN_GAME) {
HitResult hitResult = mc.crosshairTarget;
if (hitResult != null && hitResult.getType() == HitResult.Type.ENTITY) {
PlayerEntity player = (PlayerEntity) ((EntityHitResult) hitResult).getEntity();
if (!FriendManager.INSTANCE.isFriend(player) && !mc.options.sneakKey.isPressed()) {
FriendManager.INSTANCE.add(new Friend(player.getName().asString()));
ChatUtils.tellPlayer("Added " + ColorUtils.green + player.getName().asString() + ColorUtils.white + " to your friends list");
}
if (mc.options.sneakKey.isPressed() && FriendManager.INSTANCE.isFriend(player)) {
for (Friend friend : FriendManager.INSTANCE.friends) {
if (friend.name == player.getName().asString()) {
FriendManager.INSTANCE.friends.remove(friend);
ChatUtils.tellPlayer("Removed " + ColorUtils.red + friend.name + ColorUtils.white + " from your friends list");
}
}
}
}
}
}
use of net.minecraft.util.hit.HitResult in project Hypnotic-Client by Hypnotic-Development.
the class BlockOutline method render3d.
@EventTarget
public void render3d(EventRender3D event) {
HitResult target = mc.crosshairTarget;
if (target != null) {
if (target.getType() == Type.BLOCK) {
BlockPos pos = (BlockPos) ((BlockHitResult) target).getBlockPos();
float[] c = color.getRGBFloat();
switch(mode.getSelected()) {
case "Box":
RenderUtils.drawBoxOutline(pos, QuadColor.single(c[0], c[1], c[2], 1), (int) width.getValue());
break;
case "Box-Fill":
RenderUtils.drawBoxOutline(pos, QuadColor.single(c[0], c[1], c[2], 1), (int) width.getValue());
RenderUtils.drawBoxFill(pos, QuadColor.single(c[0], c[1], c[2], 0.4f));
break;
case "Face":
RenderUtils.drawFaceOutline(pos, QuadColor.single(c[0], c[1], c[2], 1), (int) width.getValue(), (Direction) ((BlockHitResult) target).getSide());
break;
case "Face-Fill":
RenderUtils.drawFaceFill(pos, QuadColor.single(c[0], c[1], c[2], 0.4f), (Direction) ((BlockHitResult) target).getSide());
RenderUtils.drawFaceOutline(pos, QuadColor.single(c[0], c[1], c[2], 1), (int) width.getValue(), (Direction) ((BlockHitResult) target).getSide());
break;
}
}
}
}
Aggregations