use of net.minecraft.util.hit.EntityHitResult in project BleachHack by BleachDrinker420.
the class CmdNBT method getNbt.
private NbtCompound getNbt(String arg) {
if (arg.equalsIgnoreCase("hand")) {
return mc.player.getMainHandStack().getOrCreateNbt();
} else if (arg.equalsIgnoreCase("block")) {
HitResult target = mc.crosshairTarget;
if (target.getType() == HitResult.Type.BLOCK) {
BlockPos pos = ((BlockHitResult) target).getBlockPos();
BlockEntity be = mc.world.getBlockEntity(pos);
if (be != null) {
return be.writeNbt(new NbtCompound());
} else {
return new NbtCompound();
}
}
BleachLogger.error("Not looking at a block.");
return null;
} else if (arg.equalsIgnoreCase("entity")) {
HitResult target = mc.crosshairTarget;
if (target.getType() == HitResult.Type.ENTITY) {
return ((EntityHitResult) target).getEntity().writeNbt(new NbtCompound());
}
BleachLogger.error("Not looking at an entity.");
return null;
}
throw new CmdSyntaxException();
}
use of net.minecraft.util.hit.EntityHitResult in project fabric by FabricMC.
the class MixinServerPlayNetworkHandler method onPlayerInteractEntity.
@Inject(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;interactAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"), cancellable = true)
public void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet, CallbackInfo info) {
World world = player.getEntityWorld();
Entity entity = packet.getEntity(world);
if (entity != null) {
EntityHitResult hitResult = new EntityHitResult(entity, packet.getHitPosition().add(entity.x, entity.y, entity.z));
ActionResult result = UseEntityCallback.EVENT.invoker().interact(player, world, packet.getHand(), entity, hitResult);
if (result != ActionResult.PASS) {
info.cancel();
}
}
}
use of net.minecraft.util.hit.EntityHitResult in project Client by MatHax.
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.EntityHitResult in project Client by MatHax.
the class Freecam method onTick.
@EventHandler
private void onTick(TickEvent.Post event) {
if (mc.cameraEntity.isInsideWall())
mc.getCameraEntity().noClip = true;
if (!perspective.isFirstPerson())
mc.options.setPerspective(Perspective.FIRST_PERSON);
Vec3d forward = Vec3d.fromPolar(0, yaw);
Vec3d right = Vec3d.fromPolar(0, yaw + 90);
double velX = 0;
double velY = 0;
double velZ = 0;
if (rotate.get()) {
BlockPos crossHairPos;
Vec3d crossHairPosition;
if (mc.crosshairTarget instanceof EntityHitResult) {
crossHairPos = ((EntityHitResult) mc.crosshairTarget).getEntity().getBlockPos();
Rotations.rotate(Rotations.getYaw(crossHairPos), Rotations.getPitch(crossHairPos), 0, null);
} else {
crossHairPosition = mc.crosshairTarget.getPos();
crossHairPos = ((BlockHitResult) mc.crosshairTarget).getBlockPos();
if (!mc.world.getBlockState(crossHairPos).isAir())
Rotations.rotate(Rotations.getYaw(crossHairPosition), Rotations.getPitch(crossHairPosition), 0, null);
}
}
double s = 0.5;
if (mc.options.sprintKey.isPressed())
s = 1;
boolean a = false;
if (this.forward) {
velX += forward.x * s * speedValue;
velZ += forward.z * s * speedValue;
a = true;
}
if (this.backward) {
velX -= forward.x * s * speedValue;
velZ -= forward.z * s * speedValue;
a = true;
}
boolean b = false;
if (this.right) {
velX += right.x * s * speedValue;
velZ += right.z * s * speedValue;
b = true;
}
if (this.left) {
velX -= right.x * s * speedValue;
velZ -= right.z * s * speedValue;
b = true;
}
if (a && b) {
double diagonal = 1 / Math.sqrt(2);
velX *= diagonal;
velZ *= diagonal;
}
if (this.up)
velY += s * speedValue;
if (this.down)
velY -= s * speedValue;
prevPos.set(pos);
pos.set(pos.x + velX, pos.y + velY, pos.z + velZ);
}
use of net.minecraft.util.hit.EntityHitResult in project Hypnotic-Client by Hypnotic-Development.
the class Freecam method onTick.
@Override
public void onTick() {
perspective = mc.options.getPerspective();
if (mc.cameraEntity.isInsideWall())
mc.getCameraEntity().noClip = true;
if (!perspective.isFirstPerson())
mc.options.setPerspective(Perspective.FIRST_PERSON);
if (mc.currentScreen != null)
return;
yaw = mc.cameraEntity.getYaw();
Vec3d forward = Vec3d.fromPolar(0, yaw);
Vec3d right = Vec3d.fromPolar(0, yaw + 90);
double velX = 0;
double velY = 0;
double velZ = 0;
BlockPos crossHairPos;
Vec3d crossHairPosition;
if (mc.crosshairTarget instanceof EntityHitResult) {
crossHairPos = ((EntityHitResult) mc.crosshairTarget).getEntity().getBlockPos();
RotationUtils.rotate(RotationUtils.getYaw(crossHairPos), RotationUtils.getPitch(crossHairPos), 0, null);
} else {
crossHairPosition = mc.crosshairTarget.getPos();
crossHairPos = ((BlockHitResult) mc.crosshairTarget).getBlockPos();
if (!mc.world.getBlockState(crossHairPos).isAir()) {
RotationUtils.rotate(RotationUtils.getYaw(crossHairPosition), RotationUtils.getPitch(crossHairPosition), 0, null);
}
}
double s = 0.5;
if (mc.options.sprintKey.isPressed())
s = 1;
boolean a = false;
if (this.forward) {
velX += forward.x * s * speed.getValue();
velZ += forward.z * s * speed.getValue();
a = true;
}
if (this.backward) {
velX -= forward.x * s * speed.getValue();
velZ -= forward.z * s * speed.getValue();
a = true;
}
boolean b = false;
if (this.right) {
velX += right.x * s * speed.getValue();
velZ += right.z * s * speed.getValue();
b = true;
}
if (this.left) {
velX -= right.x * s * speed.getValue();
velZ -= right.z * s * speed.getValue();
b = true;
}
if (a && b) {
double diagonal = 1 / Math.sqrt(2);
velX *= diagonal;
velZ *= diagonal;
}
if (this.up) {
velY += s * speed.getValue();
}
if (this.down) {
velY -= s * speed.getValue();
}
prevPos.set(pos);
pos.set(pos.x + velX, pos.y + velY, pos.z + velZ);
super.onTick();
}
Aggregations