use of net.minecraft.util.hit.EntityHitResult in project HWG by cybercat-mods.
the class RocketEntity method tick.
@Override
public void tick() {
super.tick();
boolean bl = this.isNoClip();
Vec3d vec3d = this.getVelocity();
if (this.prevPitch == 0.0F && this.prevYaw == 0.0F) {
double f = vec3d.horizontalLength();
this.setYaw((float) (MathHelper.atan2(vec3d.x, vec3d.z) * 57.2957763671875D));
this.setPitch((float) (MathHelper.atan2(vec3d.y, f) * 57.2957763671875D));
this.prevYaw = this.getYaw();
this.prevPitch = this.getPitch();
}
if (this.age >= 80) {
this.explode();
this.remove(Entity.RemovalReason.DISCARDED);
}
if (this.inAir && !bl) {
this.age();
++this.timeInAir;
} else {
this.timeInAir = 0;
Vec3d vec3d3 = this.getPos();
Vec3d vector3d3 = vec3d3.add(vec3d);
HitResult hitResult = this.world.raycast(new RaycastContext(vec3d3, vector3d3, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, this));
if (((HitResult) hitResult).getType() != HitResult.Type.MISS) {
vector3d3 = ((HitResult) hitResult).getPos();
}
while (!this.isRemoved()) {
EntityHitResult entityHitResult = this.getEntityCollision(vec3d3, vector3d3);
if (entityHitResult != null) {
hitResult = entityHitResult;
}
if (hitResult != null && ((HitResult) hitResult).getType() == HitResult.Type.ENTITY) {
Entity entity = ((EntityHitResult) hitResult).getEntity();
Entity entity2 = this.getOwner();
if (entity instanceof PlayerEntity && entity2 instanceof PlayerEntity && !((PlayerEntity) entity2).shouldDamagePlayer((PlayerEntity) entity)) {
hitResult = null;
entityHitResult = null;
}
}
if (hitResult != null && !bl) {
this.onCollision((HitResult) hitResult);
this.velocityDirty = true;
}
if (entityHitResult == null || this.getPierceLevel() <= 0) {
break;
}
hitResult = null;
}
vec3d = this.getVelocity();
double d = vec3d.x;
double e = vec3d.y;
double g = vec3d.z;
double h = this.getX() + d;
double j = this.getY() + e;
double k = this.getZ() + g;
double l = vec3d.horizontalLength();
if (bl) {
this.setYaw((float) (MathHelper.atan2(-e, -g) * 57.2957763671875D));
} else {
this.setYaw((float) (MathHelper.atan2(e, g) * 57.2957763671875D));
}
this.setPitch((float) (MathHelper.atan2(e, l) * 57.2957763671875D));
this.setPitch(updateRotation(this.prevPitch, this.getPitch()));
this.setYaw(updateRotation(this.prevYaw, this.getYaw()));
float m = 0.99F;
this.setVelocity(vec3d.multiply((double) m));
if (!this.hasNoGravity() && !bl) {
Vec3d vec3d5 = this.getVelocity();
this.setVelocity(vec3d5.x, vec3d5.y - 0.05000000074505806D, vec3d5.z);
}
this.updatePosition(h, j, k);
this.checkBlockCollision();
}
}
use of net.minecraft.util.hit.EntityHitResult in project alaskanativecraft by Platymemo.
the class MinecraftClientMixin method pickDogsledItem.
@Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/util/hit/EntityHitResult;getEntity()Lnet/minecraft/entity/Entity;", ordinal = 0), method = "doItemPick", cancellable = true)
private void pickDogsledItem(CallbackInfo ci) {
Entity entity = ((EntityHitResult) this.crosshairTarget).getEntity();
if (entity instanceof DogsledEntity) {
ItemStack pickedDogsled = new ItemStack(((DogsledEntity) entity).asItem());
PlayerInventory playerInventory = this.player.getInventory();
int i = playerInventory.getSlotWithStack(pickedDogsled);
if (this.player.getAbilities().creativeMode) {
playerInventory.addPickBlock(pickedDogsled);
this.interactionManager.clickCreativeStack(this.player.getStackInHand(Hand.MAIN_HAND), 36 + playerInventory.selectedSlot);
} else if (i != -1) {
if (PlayerInventory.isValidHotbarIndex(i)) {
playerInventory.selectedSlot = i;
} else {
this.interactionManager.pickFromInventory(i);
}
}
ci.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 libr-getter by gXLg.
the class LibrGetCommand method runSelector.
private static int runSelector(CommandContext<FabricClientCommandSource> context) {
if (Worker.getState() != Worker.State.STANDBY) {
context.getSource().sendFeedback(new LiteralText("LibrGetter is running!").formatted(Formatting.RED));
return 1;
}
MinecraftClient client = MinecraftClient.getInstance();
ClientWorld world = client.world;
if (world == null) {
context.getSource().sendFeedback(new LiteralText("InternalError: world == null").formatted(Formatting.RED));
return 1;
}
ClientPlayerEntity player = client.player;
if (player == null) {
context.getSource().sendFeedback(new LiteralText("InternalError: player == null").formatted(Formatting.RED));
return 1;
}
HitResult hit = client.crosshairTarget;
if (hit == null) {
context.getSource().sendFeedback(new LiteralText("InternalError: hit == null").formatted(Formatting.RED));
return 1;
}
HitResult.Type hitType = hit.getType();
if (hitType == HitResult.Type.MISS) {
context.getSource().sendFeedback(new LiteralText("You are not targeting anything!").formatted(Formatting.RED));
return 1;
}
if (hitType == HitResult.Type.BLOCK) {
BlockPos blockPos = ((BlockHitResult) hit).getBlockPos();
if (!world.getBlockState(blockPos).isOf(Blocks.LECTERN)) {
context.getSource().sendFeedback(new LiteralText("Block is not a lectern!").formatted(Formatting.RED));
return 1;
}
Worker.setBlock(blockPos);
context.getSource().sendFeedback(new LiteralText("Block selected"));
} else if (hitType == HitResult.Type.ENTITY) {
EntityHitResult entityHitResult = (EntityHitResult) hit;
Entity entity = entityHitResult.getEntity();
if (!(entity instanceof MerchantEntity)) {
context.getSource().sendFeedback(new LiteralText("Entity is not a villager!").formatted(Formatting.RED));
return 1;
}
VillagerEntity villager = (VillagerEntity) entity;
if (villager.getVillagerData().getProfession() != VillagerProfession.LIBRARIAN) {
context.getSource().sendFeedback(new LiteralText("Villager is not a librarian!").formatted(Formatting.RED));
return 1;
}
context.getSource().sendFeedback(new LiteralText("Villager selected"));
Worker.setVillager(villager);
}
return 0;
}
Aggregations