Search in sources :

Example 6 with Vector3d

use of net.minecraft.util.math.vector.Vector3d in project Overloaded by CJ-MC-Mods.

the class ItemRayGun method handleMessage.

public void handleMessage(ServerPlayerEntity player, RayGunMessage message) {
    ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
    if (itemStack.getItem() != this) {
        return;
    }
    LazyOptional<IEnergyStorage> opEnergy = itemStack.getCapability(ENERGY);
    if (!opEnergy.isPresent()) {
        Overloaded.logger.warn("Railgun has no Energy Capability? NBT: " + itemStack.getTag());
        return;
    }
    IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    if (energy.getEnergyStored() < OverloadedConfig.INSTANCE.rayGun.energyPerShot) {
        player.displayClientMessage(new StringTextComponent("Not enough power to fire."), true);
        return;
    }
    Vector3d eyePos = player.getEyePosition(1);
    if (eyePos.distanceTo(message.vector) > OverloadedConfig.INSTANCE.rayGun.maxRange) {
        player.displayClientMessage(new StringTextComponent("Target out of range."), true);
        return;
    }
    BlockRayTraceResult sanityCheckVec = player.level.clip(new RayTraceContext(eyePos, message.vector, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, player));
    if (sanityCheckVec.getType() != RayTraceResult.Type.MISS) {
        player.displayClientMessage(new StringTextComponent("Target no longer in sight."), true);
        return;
    }
    energy.extractEnergy(OverloadedConfig.INSTANCE.rayGun.energyPerShot, false);
    LightningBoltEntity entity = new LightningBoltEntity(EntityType.LIGHTNING_BOLT, player.level);
    entity.moveTo(message.vector.x, message.vector.y, message.vector.z, 0, 0);
    player.level.addFreshEntity(entity);
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) RayTraceContext(net.minecraft.util.math.RayTraceContext) LightningBoltEntity(net.minecraft.entity.effect.LightningBoltEntity) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) StringTextComponent(net.minecraft.util.text.StringTextComponent) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) ItemStack(net.minecraft.item.ItemStack)

Example 7 with Vector3d

use of net.minecraft.util.math.vector.Vector3d in project Overloaded by CJ-MC-Mods.

the class ItemRailGun method handleFireMessage.

public void handleFireMessage(@Nonnull ServerPlayerEntity player, @Nonnull RailGunFireMessage message) {
    ItemStack itemStack = player.getItemInHand(message.hand);
    if (itemStack.getItem() != this) {
        return;
    }
    LazyOptional<IEnergyStorage> opEnergy = itemStack.getCapability(ENERGY);
    if (!opEnergy.isPresent()) {
        Overloaded.logger.warn("RailGun has no Energy Capability? NBT: " + itemStack.getTag());
        return;
    }
    IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    LazyOptional<IGenericDataStorage> opSettingCapability = itemStack.getCapability(GENERIC_DATA_STORAGE);
    if (!opSettingCapability.isPresent()) {
        Overloaded.logger.warn("RailGun has no GenericData Capability? NBT: " + itemStack.getTag());
        return;
    }
    IGenericDataStorage settingCapability = opSettingCapability.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    settingCapability.suggestUpdate();
    int energyRequired = settingCapability.getIntegerMap().getOrDefault(RAILGUN_POWER_KEY, OverloadedConfig.INSTANCE.railGun.minEnergy);
    if (energy.getEnergyStored() < energyRequired) {
        player.displayClientMessage(new StringTextComponent("Not enough power to fire."), true);
        return;
    }
    int energyExtracted = energy.extractEnergy(energyRequired, false);
    @Nullable Entity entity = player.level.getEntity(message.id);
    if (entity == null || !entity.isAlive()) {
        return;
    } else if (player.distanceTo(entity) > OverloadedConfig.INSTANCE.rayGun.maxRange) {
        player.displayClientMessage(new StringTextComponent("Target out of range."), true);
    } else if (entity.hurt(DamageSource.playerAttack(player), (float) (OverloadedConfig.INSTANCE.railGun.damagePerRF * energyExtracted))) {
        Vector3d knockback = message.moveVector.scale(energyExtracted * OverloadedConfig.INSTANCE.railGun.knockbackPerRF);
        entity.push(knockback.x, knockback.y, knockback.z);
    }
}
Also used : IGenericDataStorage(com.cjm721.overloaded.storage.IGenericDataStorage) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 8 with Vector3d

use of net.minecraft.util.math.vector.Vector3d in project Overloaded by CJ-MC-Mods.

the class WorldUtil method rayTraceWithEntities.

public static RayTraceResult rayTraceWithEntities(@Nonnull World world, @Nonnull Vector3d startingLocation, @Nonnull Vector3d direction, @Nonnull Entity excludedEntity, double maxDistance) {
    Vector3d endingLocation = startingLocation.add(direction.scale(maxDistance));
    BlockRayTraceResult rayTraceResult = world.clip(new RayTraceContext(startingLocation, endingLocation, RayTraceContext.BlockMode.COLLIDER, RayTraceContext.FluidMode.NONE, excludedEntity));
    if (rayTraceResult.getType() != RayTraceResult.Type.MISS) {
        endingLocation = new Vector3d(rayTraceResult.getLocation().x, rayTraceResult.getLocation().y, rayTraceResult.getLocation().z);
    }
    Entity entity = null;
    double[] vertexes = new double[6];
    vertexes[0] = startingLocation.x - 0.5D;
    vertexes[1] = startingLocation.y - 0.5D;
    vertexes[2] = startingLocation.z - 0.5D;
    vertexes[3] = startingLocation.x + 0.5D;
    vertexes[4] = startingLocation.y + 0.5D;
    vertexes[5] = startingLocation.z + 0.5D;
    int length = (int) Math.ceil(startingLocation.subtract(endingLocation).length());
    for (double i = 0; i < length; i += 0.1) {
        vertexes[0] += direction.x * i;
        vertexes[1] += direction.y * i;
        vertexes[2] += direction.z * i;
        vertexes[3] += direction.x * i;
        vertexes[4] += direction.y * i;
        vertexes[5] += direction.z * i;
        AxisAlignedBB boundingBox = new AxisAlignedBB(vertexes[0], vertexes[1], vertexes[2], vertexes[3], vertexes[4], vertexes[5]);
        List<Entity> list = world.getEntities(excludedEntity, boundingBox);
        double smallestEntityDistance = 0.0D;
        for (Entity entity1 : list) {
            if (entity1.isPickable() && (!entity1.is(excludedEntity)) && !entity1.noPhysics) {
                AxisAlignedBB axisalignedbb = entity1.getBoundingBox().inflate(0.30000001192092896D);
            // RayTraceResult intercept =
            // axisalignedbb.intersects(startingLocation, endingLocation);
            // 
            // if (intercept != null && intercept.hitVec != null) {
            // double currentEntityDistance =
            // startingLocation.squareDistanceTo(intercept.hitVec);
            // 
            // if (currentEntityDistance < smallestEntityDistance || smallestEntityDistance
            // == 0.0D) {
            // entity = entity1;
            // smallestEntityDistance = currentEntityDistance;
            // }
            // }
            }
        }
        if (entity != null) {
        // RayTraceResult intercept = boundingBox.calculateIntercept(startingLocation,
        // endingLocation);
        // 
        // if (intercept != null) {
        // Vec3d hitVec = intercept.hitVec;
        // return new RayTraceResult(entity, hitVec == null ? new Vec3d(0.5, 0.5, 0.5) :
        // hitVec);
        // }
        }
    }
    return rayTraceResult;
}
Also used : Entity(net.minecraft.entity.Entity) Vector3d(net.minecraft.util.math.vector.Vector3d)

Example 9 with Vector3d

use of net.minecraft.util.math.vector.Vector3d in project AgriCraft by AgriCraft.

the class TileEntitySeedAnalyzer method calculateObserverPosition.

protected Vector3d calculateObserverPosition(double fov) {
    // calculate offset from the center of the looking glass based on fov
    double d = 0.75 * (0.5 / Math.tan(Math.PI * fov / 360));
    double dy = d * MathHelper.sin((float) Math.PI * 67.5F / 180);
    double dx = d * MathHelper.cos((float) Math.PI * 67.5F / 180);
    // fetch orientation, to determine the center of the looking glass
    BlockState state = this.getBlockState();
    Direction dir = BlockSeedAnalyzer.ORIENTATION.fetch(state);
    // apply observer position (center of looking glass + fov offset)
    return this.observerPosition = new Vector3d(this.getPos().getX() + 0.5 + (dx + 0.3125) * dir.getXOffset(), this.getPos().getY() + 0.6875 + dy, this.getPos().getZ() + 0.5 + (dx + 0.3125) * dir.getZOffset());
}
Also used : BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) Direction(net.minecraft.util.Direction)

Example 10 with Vector3d

use of net.minecraft.util.math.vector.Vector3d in project AgriCraft by AgriCraft.

the class BlockGreenHouseAirRenderer method highlightGreenHouseAirBlocks.

protected void highlightGreenHouseAirBlocks(World world, BlockPos origin, MatrixStack transforms) {
    IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
    IVertexBuilder builder = buffer.getBuffer(this.getRenderType());
    transforms.push();
    Vector3d projectedView = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
    transforms.translate(-projectedView.x, -projectedView.y, -projectedView.z);
    Matrix4f matrix4f = transforms.getLast().getMatrix();
    BlockPos.Mutable pos = origin.toMutable();
    for (int x = -RANGE; x <= RANGE; x++) {
        for (int y = -RANGE; y <= RANGE; y++) {
            for (int z = -RANGE; z <= RANGE; z++) {
                pos.setPos(origin.getX() + x, origin.getY() + y, origin.getZ() + z);
                if (world.getBlockState(pos).getBlock() instanceof BlockGreenHouseAir) {
                    this.renderWireFrameCube(builder, matrix4f, pos);
                }
            }
        }
    }
    transforms.pop();
    buffer.finish(this.getRenderType());
}
Also used : Matrix4f(net.minecraft.util.math.vector.Matrix4f) BlockGreenHouseAir(com.infinityraider.agricraft.content.world.BlockGreenHouseAir) Vector3d(net.minecraft.util.math.vector.Vector3d) IRenderTypeBuffer(net.minecraft.client.renderer.IRenderTypeBuffer) BlockPos(net.minecraft.util.math.BlockPos) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder)

Aggregations

Vector3d (net.minecraft.util.math.vector.Vector3d)19 BlockPos (net.minecraft.util.math.BlockPos)7 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 ItemStack (net.minecraft.item.ItemStack)4 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)4 Nullable (javax.annotation.Nullable)3 BlockState (net.minecraft.block.BlockState)3 Entity (net.minecraft.entity.Entity)3 IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)3 IVertexBuilder (com.mojang.blaze3d.vertex.IVertexBuilder)2 Nonnull (javax.annotation.Nonnull)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 Direction (net.minecraft.util.Direction)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 RayTraceContext (net.minecraft.util.math.RayTraceContext)2 Matrix4f (net.minecraft.util.math.vector.Matrix4f)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 BlockBPMultipart (com.bluepowermod.block.BlockBPMultipart)1