Search in sources :

Example 1 with BoundingBox

use of team.cqr.cqrepoured.util.math.BoundingBox in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAISpectreLordDash method dashToTarget.

private void dashToTarget() {
    Vector3d vec1 = this.entity.position();
    boolean noClip = this.entity.noPhysics;
    if (!noClip) {
        Vector3d start = new Vector3d(this.entity.getX(), this.entity.getY() + this.entity.getEyeHeight(), this.entity.getZ());
        Vector3d end = start.add(this.targetDirection);
        RayTraceContext rtc = new RayTraceContext(start, end, BlockMode.COLLIDER, FluidMode.ANY, null);
        if (this.world.clip(rtc) == null && this.world.noCollision(this.entity.getBoundingBox().move(this.targetDirection))) {
            this.entity.noPhysics = true;
        }
    }
    this.entity.move(MoverType.SELF, this.targetDirection);
    this.entity.noPhysics = noClip;
    Vector3d vec2 = this.entity.position();
    Vector3d vec3 = new Vector3d(-this.dashWidth, 0.0D, 0.0D);
    Vector3d vec4 = new Vector3d(this.dashWidth, this.entity.getBbHeight(), vec2.subtract(vec1).length());
    BoundingBox bb = new BoundingBox(vec3, vec4, this.yawRadian, 0.0D, vec1);
    List<LivingEntity> list = BoundingBox.getEntitiesInsideBB(this.world, this.entity, LivingEntity.class, bb);
    Faction faction = this.entity.getFaction();
    for (LivingEntity entity : list) {
        if (!TargetUtil.PREDICATE_ATTACK_TARGET.apply(entity)) {
            continue;
        }
        if (faction != null && faction.isAlly(entity)) {
            continue;
        }
        entity.hurt(DamageSource.mobAttack(this.entity).bypassArmor(), 10.0F);
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) RayTraceContext(net.minecraft.util.math.RayTraceContext) BoundingBox(team.cqr.cqrepoured.util.math.BoundingBox) Faction(team.cqr.cqrepoured.faction.Faction)

Example 2 with BoundingBox

use of team.cqr.cqrepoured.util.math.BoundingBox in project ChocolateQuestRepoured by TeamChocoQuest.

the class EntityAIAttackSpecialSpear method stopAttack.

@Override
public void stopAttack(AbstractEntityCQR attacker, LivingEntity target) {
    Vector3d vec1 = attacker.getEyePosition(1.0F);
    double x = target.getX() - vec1.x;
    double y = MathHelper.clamp(vec1.y, target.getY(), target.getY() + target.getBbHeight()) - vec1.y;
    double z = target.getZ() - vec1.z;
    double dist = MathHelper.sqrt(x * x + z * z);
    double yaw = MathHelper.atan2(-x, z);
    double pitch = MathHelper.atan2(-y, dist);
    Vector3d vec2 = Vector3d.directionFromRotation((float) Math.toDegrees(pitch), (float) Math.toDegrees(yaw));
    ItemStack stack = attacker.getMainHandItem();
    ItemSpearBase item = ((ItemSpearBase) stack.getItem());
    double reachDistance = attacker.getBbWidth() + 0.85D + item.getReach() * 2.5D;
    BoundingBox bb = new BoundingBox(new Vector3d(-0.25D, -0.25D, 0.0D), new Vector3d(0.25D, 0.25D, reachDistance), yaw, pitch, vec1);
    for (LivingEntity entity : BoundingBox.getEntitiesInsideBB(attacker.level, attacker, LivingEntity.class, bb)) {
        if (!attacker.getFaction().isAlly(entity)) {
            // TODO apply enchantments
            entity.hurt(DamageSource.mobAttack(attacker), 1.0F + item.getDamage());
        }
    }
    Vector3d vec3 = vec1.add(new Vector3d(-0.4D, -0.5D, 0.0D).xRot((float) -pitch).yRot((float) -yaw));
    for (double d = reachDistance; d >= 0.0D; d--) {
        Vector3d vec4 = vec3.add(vec2.scale(d));
        ((ServerWorld) attacker.level).sendParticles(ParticleTypes.SMOKE, vec4.x, vec4.y, vec4.z, 1, 0, 0, 0, 0.05);
    }
    attacker.level.playSound(null, attacker.getX(), attacker.getY(), attacker.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, attacker.getSoundSource(), 1.0F, 1.0F);
    attacker.swing(Hand.MAIN_HAND);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) ServerWorld(net.minecraft.world.server.ServerWorld) Vector3d(net.minecraft.util.math.vector.Vector3d) ItemSpearBase(team.cqr.cqrepoured.item.spear.ItemSpearBase) BoundingBox(team.cqr.cqrepoured.util.math.BoundingBox) ItemStack(net.minecraft.item.ItemStack)

Example 3 with BoundingBox

use of team.cqr.cqrepoured.util.math.BoundingBox in project ChocolateQuestRepoured by TeamChocoQuest.

the class AbstractEntityLaser method baseTick.

@Override
public void baseTick() {
    if (!this.level.isClientSide && !this.caster.isAlive()) {
        this.remove();
    }
    super.baseTick();
    this.prevRotationYawCQR = this.rotationYawCQR;
    this.prevRotationPitchCQR = this.rotationPitchCQR;
    if (this.level.isClientSide) {
        this.rotationYawCQR = this.serverRotationYawCQR;
        this.rotationPitchCQR = this.serverRotationPitchCQR;
    } else {
        this.updatePositionAndRotation();
        CQRMain.NETWORK.send(PacketDistributor.TRACKING_ENTITY.with(this::getEntity), new SPacketSyncLaserRotation(this));
    }
    if (!this.level.isClientSide) {
        Vector3d start = this.position();
        Vector3d end = start.add(Vector3d.directionFromRotation(this.rotationPitchCQR, this.rotationYawCQR).scale(this.length));
        RayTraceContext rtc = new RayTraceContext(start, end, BlockMode.COLLIDER, FluidMode.NONE, null);
        // this.level.rayTraceBlocks(start, end, false, false, false);
        RayTraceResult result = this.level.clip(rtc);
        double d = result != null ? (float) result.getLocation().subtract(this.position()).length() : this.length;
        if (result != null) {
            BlockPos pos = new BlockPos(result.getLocation());
            BlockState state = this.level.getBlockState(pos);
            if (this.canHitBlock(pos, state)) {
                float breakProgress = this.onHitBlock(pos, state);
                if (breakProgress > 0.0F) {
                    if (breakProgress >= 1.0F) {
                        // destroy block
                        this.level.destroyBlock(pos, true);
                    } else {
                        BreakingInfo breakingInfo = this.blockBreakMap.computeIfAbsent(pos, key -> new BreakingInfo());
                        breakingInfo.lastTimeHit = this.tickCount;
                        breakingInfo.progress += breakProgress;
                        if (breakingInfo.progress >= 1.0F) {
                            // destroy block
                            this.level.destroyBlock(pos, true);
                            this.blockBreakMap.remove(pos);
                            int i = 0x1000000 + this.getId() * 256 + breakingInfo.id;
                            this.level.destroyBlockProgress(i, pos, -1);
                        }
                    }
                }
            }
        }
        Iterator<Map.Entry<BlockPos, BreakingInfo>> iterator = this.blockBreakMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<BlockPos, BreakingInfo> entry = iterator.next();
            BreakingInfo breakingInfo = entry.getValue();
            if (this.tickCount - breakingInfo.lastTimeHit >= this.blockBreakThreshhold()) {
                breakingInfo.progress -= this.blockBreakRevert();
            }
            int i = 0x1000000 + this.getId() * 256 + breakingInfo.id;
            if (breakingInfo.progress <= 0.0F) {
                iterator.remove();
                this.level.destroyBlockProgress(i, entry.getKey(), -1);
            } else {
                this.level.destroyBlockProgress(i, entry.getKey(), (int) (breakingInfo.progress * 10.0F));
            }
        }
        Vector3d vec1 = new Vector3d(-this.laserEffectRadius(), -this.laserEffectRadius(), 0.0D);
        Vector3d vec2 = new Vector3d(this.laserEffectRadius(), this.laserEffectRadius(), d);
        BoundingBox bb = new BoundingBox(vec1, vec2, Math.toRadians(this.rotationYawCQR), Math.toRadians(this.rotationPitchCQR), start);
        for (LivingEntity entity : BoundingBox.getEntitiesInsideBB(this.level, this.caster, LivingEntity.class, bb)) {
            if (this.canHitEntity(entity) && this.tickCount - this.hitInfoMap.getInt(entity) >= this.getEntityHitRate()) {
                this.onEntityHit(entity);
                this.hitInfoMap.put(entity, this.tickCount);
            }
        }
    }
}
Also used : SPacketSyncLaserRotation(team.cqr.cqrepoured.network.server.packet.SPacketSyncLaserRotation) RayTraceContext(net.minecraft.util.math.RayTraceContext) RayTraceResult(net.minecraft.util.math.RayTraceResult) LivingEntity(net.minecraft.entity.LivingEntity) BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) BoundingBox(team.cqr.cqrepoured.util.math.BoundingBox) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Map(java.util.Map) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap)

Example 4 with BoundingBox

use of team.cqr.cqrepoured.util.math.BoundingBox in project ChocolateQuestRepoured by TeamChocoQuest.

the class AbstractEntityLaser method baseTick.

@Override
public void baseTick() {
    if (!this.level.isClientSide && !this.caster.isAlive()) {
        this.remove();
    }
    super.baseTick();
    this.prevRotationYawCQR = this.rotationYawCQR;
    this.prevRotationPitchCQR = this.rotationPitchCQR;
    if (this.level.isClientSide) {
        this.rotationYawCQR = this.serverRotationYawCQR;
        this.rotationPitchCQR = this.serverRotationPitchCQR;
    } else {
        this.updatePositionAndRotation();
        CQRMain.NETWORK.send(PacketDistributor.TRACKING_ENTITY.with(this::getEntity), new SPacketSyncLaserRotation(this));
    }
    if (!this.level.isClientSide) {
        Vector3d start = this.getPositionVector();
        Vector3d end = start.add(Vector3d.directionFromRotation(this.rotationPitchCQR, this.rotationYawCQR).scale(this.length));
        RayTraceResult result = this.level.rayTraceBlocks(start, end, false, false, false);
        double d = result != null ? (float) result.getLocation().subtract(this.getPositionVector()).length() : this.length;
        if (result != null) {
            BlockPos pos = new BlockPos(result.getLocation());
            BlockState state = this.level.getBlockState(pos);
            if (this.canHitBlock(pos, state)) {
                float breakProgress = this.onHitBlock(pos, state);
                if (breakProgress > 0.0F) {
                    if (breakProgress >= 1.0F) {
                        // destroy block
                        this.level.destroyBlock(pos, true);
                    } else {
                        BreakingInfo breakingInfo = this.blockBreakMap.computeIfAbsent(pos, key -> new BreakingInfo());
                        breakingInfo.lastTimeHit = this.tickCount;
                        breakingInfo.progress += breakProgress;
                        if (breakingInfo.progress >= 1.0F) {
                            // destroy block
                            this.level.destroyBlock(pos, true);
                            this.blockBreakMap.remove(pos);
                            int i = 0x1000000 + this.getEntity() * 256 + breakingInfo.id;
                            this.level.sendBlockBreakProgress(i, pos, -1);
                        }
                    }
                }
            }
        }
        Iterator<Map.Entry<BlockPos, BreakingInfo>> iterator = this.blockBreakMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<BlockPos, BreakingInfo> entry = iterator.next();
            BreakingInfo breakingInfo = entry.getValue();
            if (this.tickCount - breakingInfo.lastTimeHit >= this.blockBreakThreshhold()) {
                breakingInfo.progress -= this.blockBreakRevert();
            }
            int i = 0x1000000 + this.getId() * 256 + breakingInfo.id;
            if (breakingInfo.progress <= 0.0F) {
                iterator.remove();
                this.level.sendBlockBreakProgress(i, entry.getKey(), -1);
            } else {
                this.level.sendBlockBreakProgress(i, entry.getKey(), (int) (breakingInfo.progress * 10.0F));
            }
        }
        Vector3d vec1 = new Vector3d(-this.laserEffectRadius(), -this.laserEffectRadius(), 0.0D);
        Vector3d vec2 = new Vector3d(this.laserEffectRadius(), this.laserEffectRadius(), d);
        BoundingBox bb = new BoundingBox(vec1, vec2, Math.toRadians(this.rotationYawCQR), Math.toRadians(this.rotationPitchCQR), start);
        for (LivingEntity entity : BoundingBox.getEntitiesInsideBB(this.level, this.caster, LivingEntity.class, bb)) {
            if (this.canHitEntity(entity) && this.tickCount - this.hitInfoMap.getInt(entity) >= this.getEntityHitRate()) {
                this.onEntityHit(entity);
                this.hitInfoMap.put(entity, this.tickCount);
            }
        }
    }
}
Also used : SPacketSyncLaserRotation(team.cqr.cqrepoured.network.server.packet.SPacketSyncLaserRotation) RayTraceResult(net.minecraft.util.math.RayTraceResult) LivingEntity(net.minecraft.entity.LivingEntity) BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) BoundingBox(team.cqr.cqrepoured.util.math.BoundingBox) BlockPos(net.minecraft.util.math.BlockPos) HashMap(java.util.HashMap) Object2IntMap(it.unimi.dsi.fastutil.objects.Object2IntMap) Map(java.util.Map) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)

Aggregations

LivingEntity (net.minecraft.entity.LivingEntity)4 Vector3d (net.minecraft.util.math.vector.Vector3d)4 BoundingBox (team.cqr.cqrepoured.util.math.BoundingBox)4 Object2IntMap (it.unimi.dsi.fastutil.objects.Object2IntMap)2 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BlockState (net.minecraft.block.BlockState)2 BlockPos (net.minecraft.util.math.BlockPos)2 RayTraceContext (net.minecraft.util.math.RayTraceContext)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 SPacketSyncLaserRotation (team.cqr.cqrepoured.network.server.packet.SPacketSyncLaserRotation)2 ItemStack (net.minecraft.item.ItemStack)1 ServerWorld (net.minecraft.world.server.ServerWorld)1 Faction (team.cqr.cqrepoured.faction.Faction)1 ItemSpearBase (team.cqr.cqrepoured.item.spear.ItemSpearBase)1