Search in sources :

Example 11 with RaycastContext

use of net.minecraft.world.RaycastContext in project meteor-rejects by AntiCope.

the class Lavacast method getDistance.

private void getDistance(Vec3i offset) {
    BlockPos pos = placeFluidPos.down().add(offset);
    int new_dist;
    final BlockHitResult result = mc.world.raycast(new RaycastContext(Vec3d.ofCenter(pos), Vec3d.ofCenter(pos.down(250)), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player));
    if (result == null || result.getType() != HitResult.Type.BLOCK) {
        return;
    }
    new_dist = placeFluidPos.getY() - result.getBlockPos().getY();
    if (new_dist > dist)
        dist = new_dist;
}
Also used : RaycastContext(net.minecraft.world.RaycastContext) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Example 12 with RaycastContext

use of net.minecraft.world.RaycastContext in project BleachHack by BleachDrinker420.

the class ProjectileSimulator method simulate.

public static Triple<List<Vec3d>, Entity, BlockPos> simulate(Entity e) {
    List<Vec3d> vecs = new ArrayList<>();
    SimulatedProjectile spoofE = new SimulatedProjectile(e);
    for (int i = 0; i < 100; i++) {
        Vec3d vel = spoofE.velocity;
        Vec3d newVec = spoofE.getPos().add(vel);
        // EntityHitResult entityHit = ProjectileUtil.raycast(mc.player, e.getPos(),
        // newVec, e.getBoundingBox(), null, 1f);
        List<LivingEntity> entities = mc.world.getEntitiesByClass(LivingEntity.class, spoofE.getBoundingBox().expand(0.15), EntityPredicates.VALID_LIVING_ENTITY.and(en -> en != mc.player && en != e));
        if (!entities.isEmpty()) {
            return Triple.of(vecs, entities.get(0), null);
        }
        BlockHitResult blockHit = mc.world.raycast(new RaycastContext(spoofE.getPos(), newVec, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, e));
        if (blockHit.getType() != HitResult.Type.MISS) {
            vecs.add(blockHit.getPos());
            return Triple.of(vecs, null, blockHit.getBlockPos());
        }
        float prevPitch = spoofE.pitch;
        spoofE.pitch = MathHelper.lerp(0.2F, spoofE.prevPitch, spoofE.pitch);
        spoofE.prevPitch = prevPitch;
        double gravity = e instanceof PotionEntity ? 0.05 : e instanceof ExperienceBottleEntity ? 0.07 : e instanceof ThrownEntity ? 0.03 : 0.05000000074505806;
        spoofE.velocity = new Vec3d(vel.x * 0.99, vel.y * 0.99 - gravity, vel.z * 0.99);
        spoofE.setPos(spoofE.getPos().x + spoofE.velocity.x, spoofE.getPos().y + spoofE.velocity.y, spoofE.getPos().z + spoofE.velocity.z);
        vecs.add(spoofE.getPos());
    }
    return Triple.of(vecs, null, null);
}
Also used : Entity(net.minecraft.entity.Entity) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) Box(net.minecraft.util.math.Box) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) BlockHitResult(net.minecraft.util.hit.BlockHitResult) net.minecraft.item(net.minecraft.item) BlockPos(net.minecraft.util.math.BlockPos) TridentEntity(net.minecraft.entity.projectile.TridentEntity) ThrownEntity(net.minecraft.entity.projectile.thrown.ThrownEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) ArrayList(java.util.ArrayList) HitResult(net.minecraft.util.hit.HitResult) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) List(java.util.List) Vec3d(net.minecraft.util.math.Vec3d) MathHelper(net.minecraft.util.math.MathHelper) EntityPredicates(net.minecraft.predicate.entity.EntityPredicates) RaycastContext(net.minecraft.world.RaycastContext) MinecraftClient(net.minecraft.client.MinecraftClient) Triple(org.apache.commons.lang3.tuple.Triple) RaycastContext(net.minecraft.world.RaycastContext) ThrownEntity(net.minecraft.entity.projectile.thrown.ThrownEntity) ArrayList(java.util.ArrayList) Vec3d(net.minecraft.util.math.Vec3d) PotionEntity(net.minecraft.entity.projectile.thrown.PotionEntity) LivingEntity(net.minecraft.entity.LivingEntity) ExperienceBottleEntity(net.minecraft.entity.projectile.thrown.ExperienceBottleEntity) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Example 13 with RaycastContext

use of net.minecraft.world.RaycastContext in project Hypnotic-Client by Hypnotic-Development.

the class RotationUtils method getLegitLookPos.

public static Vec3d getLegitLookPos(Box box, Direction dir, boolean raycast, int res, double extrude) {
    Vec3d eyePos = mc.player.getEyePos();
    Vec3d blockPos = new Vec3d(box.minX, box.minY, box.minZ).add((dir == Direction.WEST ? -extrude : dir.getOffsetX() * box.getXLength() + extrude), (dir == Direction.DOWN ? -extrude : dir.getOffsetY() * box.getYLength() + extrude), (dir == Direction.NORTH ? -extrude : dir.getOffsetZ() * box.getZLength() + extrude));
    for (double i = 0; i <= 1; i += 1d / (double) res) {
        for (double j = 0; j <= 1; j += 1d / (double) res) {
            Vec3d lookPos = blockPos.add((dir.getAxis() == Axis.X ? 0 : i * box.getXLength()), (dir.getAxis() == Axis.Y ? 0 : dir.getAxis() == Axis.Z ? j * box.getYLength() : i * box.getYLength()), (dir.getAxis() == Axis.Z ? 0 : j * box.getZLength()));
            if (eyePos.distanceTo(lookPos) > 4.55)
                continue;
            if (raycast) {
                if (mc.world.raycast(new RaycastContext(eyePos, lookPos, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, mc.player)).getType() == HitResult.Type.MISS) {
                    return lookPos;
                }
            } else {
                return lookPos;
            }
        }
    }
    return null;
}
Also used : RaycastContext(net.minecraft.world.RaycastContext) Vec3d(net.minecraft.util.math.Vec3d)

Example 14 with RaycastContext

use of net.minecraft.world.RaycastContext in project Paradise-Lost by devs-immortal.

the class FloatingBlockEntity method postTickEntities.

/**
 * Because this entity moves other entities, including the player, this entity has
 * to tick after the all other entities have ticked to prevent them phasing though this
 */
public void postTickEntities() {
    if (this.blockState.isAir()) {
        this.remove();
    } else {
        Block block = this.blockState.getBlock();
        BlockPos blockPos;
        if (this.floatTime++ == 0) {
            blockPos = this.getBlockPos();
            if (this.world.getBlockState(blockPos).isOf(block)) {
                this.world.removeBlock(blockPos, false);
            } else if (!this.world.isClient) {
                this.remove();
                return;
            }
        }
        boolean isFastFloater = (this.blockState.getBlock() == AetherBlocks.GRAVITITE_ORE || this.blockState.getBlock() == AetherBlocks.GRAVITITE_LEVITATOR || this.blockState.getBlock() == AetherBlocks.BLOCK_OF_GRAVITITE);
        if (!this.hasNoGravity()) {
            if (isFastFloater) {
                this.setVelocity(this.getVelocity().add(0.0D, 0.05D, 0.0D));
            } else {
                this.setVelocity(this.getVelocity().add(0.0D, 0.03D, 0.0D));
            }
        }
        Box oldBox = getBoundingBox();
        this.move(MovementType.SELF, this.getVelocity());
        if (!FallingBlock.canFallThrough(this.blockState)) {
            Box newBox = getBoundingBox();
            List<Entity> otherEntities = this.world.getOtherEntities(this, oldBox.union(newBox));
            for (Entity entity : otherEntities) {
                if (!(entity instanceof FloatingBlockEntity) && !entity.noClip) {
                    if (entity.getY() < newBox.maxY) {
                        entity.updatePosition(entity.getPos().x, newBox.maxY, entity.getPos().z);
                    }
                }
            }
        }
        if (!this.world.isClient) {
            blockPos = this.getBlockPos();
            boolean isConcrete = this.blockState.getBlock() instanceof ConcretePowderBlock;
            boolean shouldSolidify = isConcrete && this.world.getFluidState(blockPos).isIn(FluidTags.WATER);
            double speed = this.getVelocity().lengthSquared();
            if (isConcrete && speed > 1.0D) {
                BlockHitResult blockHitResult = this.world.raycast(new RaycastContext(new Vec3d(this.prevX, this.prevY, this.prevZ), new Vec3d(this.getX(), this.getY(), this.getZ()), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.SOURCE_ONLY, this));
                if (blockHitResult.getType() != HitResult.Type.MISS && this.world.getFluidState(blockHitResult.getBlockPos()).isIn(FluidTags.WATER)) {
                    blockPos = blockHitResult.getBlockPos();
                    shouldSolidify = true;
                }
            }
            if (!this.verticalCollision && !shouldSolidify) {
                if (!this.world.isClient) {
                    if (this.floatTime > 100 && blockPos.getY() > this.world.getHeight() + 64) {
                        if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS) && this.world.isPlayerInRange(blockPos.getX(), blockPos.getY(), blockPos.getZ(), 4)) {
                            this.dropItem(block);
                        }
                        this.remove();
                    }
                }
            } else {
                BlockState blockState = this.world.getBlockState(blockPos);
                this.setVelocity(this.getVelocity().multiply(0.7, 0.5, 0.7));
                if (blockState.getBlock() != Blocks.MOVING_PISTON) {
                    this.remove();
                    if (!this.destroyedOnLanding) {
                        boolean canReplace = blockState.canReplace(new AutomaticItemPlacementContext(this.world, blockPos, Direction.DOWN, ItemStack.EMPTY, Direction.UP));
                        if (!canReplace) {
                            canReplace = blockState.canReplace(new AutomaticItemPlacementContext(this.world, blockPos, Direction.UP, ItemStack.EMPTY, Direction.DOWN));
                        }
                        boolean canPlace = this.blockState.canPlaceAt(this.world, blockPos);
                        if (canReplace && canPlace) {
                            if (this.blockState.contains(Properties.WATERLOGGED) && this.world.getFluidState(blockPos).getFluid() == Fluids.WATER)
                                this.blockState = this.blockState.with(Properties.WATERLOGGED, true);
                            if (this.world.setBlockState(blockPos, this.blockState, 3)) {
                                if (block instanceof FloatingBlock)
                                    ((FloatingBlock) block).onEndFloating(this.world, blockPos, this.blockState, blockState);
                                if (this.blockEntityData != null && this.blockState.getBlock().hasBlockEntity()) {
                                    BlockEntity blockEntity = this.world.getBlockEntity(blockPos);
                                    if (blockEntity != null) {
                                        CompoundTag compoundTag = blockEntity.toTag(new CompoundTag());
                                        for (String keyName : this.blockEntityData.getKeys()) {
                                            Tag tag = this.blockEntityData.get(keyName);
                                            if (tag != null && !"x".equals(keyName) && !"y".equals(keyName) && !"z".equals(keyName)) {
                                                compoundTag.put(keyName, tag.copy());
                                            }
                                        }
                                        blockEntity.fromTag(this.blockState, compoundTag);
                                        blockEntity.markDirty();
                                    }
                                }
                            } else if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
                                this.dropItem(block);
                            }
                        } else if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
                            this.dropItem(block);
                        }
                    } else if (block instanceof FloatingBlock) {
                        ((FloatingBlock) block).onBroken(this.world, blockPos);
                    }
                }
            }
        }
        this.setVelocity(this.getVelocity().multiply(0.98D));
    }
}
Also used : BlockEntity(net.minecraft.block.entity.BlockEntity) AetherNonLivingEntity(com.aether.entities.AetherNonLivingEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) FloatingBlock(com.aether.blocks.FloatingBlock) RaycastContext(net.minecraft.world.RaycastContext) AutomaticItemPlacementContext(net.minecraft.item.AutomaticItemPlacementContext) FloatingBlock(com.aether.blocks.FloatingBlock) Tag(net.minecraft.nbt.Tag) CompoundTag(net.minecraft.nbt.CompoundTag) BlockHitResult(net.minecraft.util.hit.BlockHitResult) CompoundTag(net.minecraft.nbt.CompoundTag) BlockEntity(net.minecraft.block.entity.BlockEntity)

Example 15 with RaycastContext

use of net.minecraft.world.RaycastContext in project LittleMaidReBirth-Fabric by SistrScarlet.

the class TorcherMode method tick.

@Override
public void tick() {
    // 5秒経過しても置けない、または明るい地点を無視
    if (100 < ++this.timeToIgnore || 8 < mob.world.getLightLevel(placePos.up())) {
        this.placePos = null;
        this.timeToIgnore = 0;
        return;
    }
    // 距離が遠すぎる場合は無視
    if (distance * 2F < placePos.getManhattanDistance(mob.getBlockPos())) {
        this.placePos = null;
        return;
    }
    Item item = mob.getMainHandStack().getItem();
    if (!(item instanceof BlockItem)) {
        return;
    }
    if (3 * 3 < this.mob.squaredDistanceTo(placePos.getX(), placePos.getY(), placePos.getZ())) {
        if (--timeToRecalcPath < 0) {
            timeToRecalcPath = 20;
            Path path = this.mob.getNavigation().findPathTo(placePos.getX(), placePos.getY(), placePos.getZ(), 3);
            this.mob.getNavigation().startMovingAlong(path, 1);
        }
        return;
    }
    Vec3d start = mob.getCameraPosVec(1F);
    // 終端はブロックの上面
    Vec3d end = new Vec3d(placePos.getX() + 0.5D, placePos.getY() + 1D, placePos.getZ() + 0.5D);
    BlockHitResult result = mob.world.raycast(new RaycastContext(start, end, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, this.mob));
    FakePlayer fakePlayer = mob.getFakePlayer();
    if (((BlockItem) item).place(new ItemPlacementContext(new ItemUsageContext(fakePlayer, Hand.MAIN_HAND, result))).shouldSwingHand()) {
        mob.swingHand(Hand.MAIN_HAND);
        if (mob instanceof SoundPlayable) {
            ((SoundPlayable) mob).play(LMSounds.INSTALLATION);
        }
    }
    this.placePos = null;
}
Also used : Path(net.minecraft.entity.ai.pathing.Path) SoundPlayable(net.sistr.lmml.entity.compound.SoundPlayable) RaycastContext(net.minecraft.world.RaycastContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) FakePlayer(net.sistr.littlemaidrebirth.entity.FakePlayer)

Aggregations

RaycastContext (net.minecraft.world.RaycastContext)16 BlockHitResult (net.minecraft.util.hit.BlockHitResult)12 Vec3d (net.minecraft.util.math.Vec3d)11 HitResult (net.minecraft.util.hit.HitResult)4 BlockPos (net.minecraft.util.math.BlockPos)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 List (java.util.List)2 IVec3d (meteordevelopment.meteorclient.mixininterface.IVec3d)2 EventHandler (meteordevelopment.orbit.EventHandler)2 BlockEntity (net.minecraft.block.entity.BlockEntity)2 Entity (net.minecraft.entity.Entity)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 Hand (net.minecraft.util.Hand)2 Box (net.minecraft.util.math.Box)2 Direction (net.minecraft.util.math.Direction)2 BaritoneAPI (baritone.api.BaritoneAPI)1 FloatingBlock (com.aether.blocks.FloatingBlock)1 AetherNonLivingEntity (com.aether.entities.AetherNonLivingEntity)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1