Search in sources :

Example 46 with Vec3d

use of net.minecraft.util.math.Vec3d in project BetterWithAddons by DaedalusGame.

the class BoundingUtil method rayTrace2.

private static RayTraceResult rayTrace2(BlockPos pos, Vec3d start, Vec3d end, AxisAlignedBB boundingBox) {
    Vec3d vec3d = start.subtract((double) pos.getX(), (double) pos.getY(), (double) pos.getZ());
    Vec3d vec3d1 = end.subtract((double) pos.getX(), (double) pos.getY(), (double) pos.getZ());
    RayTraceResult raytraceresult = boundingBox.calculateIntercept(vec3d, vec3d1);
    return raytraceresult == null ? null : new RayTraceResult(raytraceresult.hitVec.addVector((double) pos.getX(), (double) pos.getY(), (double) pos.getZ()), raytraceresult.sideHit, pos);
}
Also used : RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d)

Example 47 with Vec3d

use of net.minecraft.util.math.Vec3d in project malmo by Microsoft.

the class ObservationFromRayImplementation method buildMouseOverData.

/**
 * Build the json object for the object under the cursor, whether it is a block or a creature.<br>
 * If there is any data to be returned, the json will be added in a subnode called "LineOfSight".
 * @param json a JSON object into which the info for the object under the mouse will be added.
 */
public static void buildMouseOverData(JsonObject json, boolean includeNBTData) {
    // We could use Minecraft.getMinecraft().objectMouseOver but it's limited to the block reach distance, and
    // doesn't register floating tile items.
    // Ideally use Minecraft.timer.renderPartialTicks - but we don't need sub-tick resolution.
    float partialTicks = 0;
    Entity viewer = Minecraft.getMinecraft().player;
    // Hard-coded for now - in future will be parameterised via the XML.
    float depth = 50;
    Vec3d eyePos = viewer.getPositionEyes(partialTicks);
    Vec3d lookVec = viewer.getLook(partialTicks);
    Vec3d searchVec = eyePos.addVector(lookVec.xCoord * depth, lookVec.yCoord * depth, lookVec.zCoord * depth);
    RayTraceResult mop = Minecraft.getMinecraft().world.rayTraceBlocks(eyePos, searchVec, false, false, false);
    RayTraceResult mopEnt = findEntity(eyePos, lookVec, depth, mop, true);
    if (mopEnt != null)
        mop = mopEnt;
    if (mop == null) {
        // Nothing under the mouse.
        return;
    }
    // Calculate ranges for player interaction:
    double hitDist = mop.hitVec.distanceTo(eyePos);
    double blockReach = Minecraft.getMinecraft().playerController.getBlockReachDistance();
    double entityReach = Minecraft.getMinecraft().playerController.extendedReach() ? 6.0 : 3.0;
    JsonObject jsonMop = new JsonObject();
    if (mop.typeOfHit == RayTraceResult.Type.BLOCK) {
        // We're looking at a block - send block data:
        jsonMop.addProperty("hitType", "block");
        jsonMop.addProperty("x", mop.hitVec.xCoord);
        jsonMop.addProperty("y", mop.hitVec.yCoord);
        jsonMop.addProperty("z", mop.hitVec.zCoord);
        IBlockState state = Minecraft.getMinecraft().world.getBlockState(mop.getBlockPos());
        List<IProperty> extraProperties = new ArrayList<IProperty>();
        DrawBlock db = MinecraftTypeHelper.getDrawBlockFromBlockState(state, extraProperties);
        jsonMop.addProperty("type", db.getType().value());
        if (db.getColour() != null)
            jsonMop.addProperty("colour", db.getColour().value());
        if (db.getVariant() != null)
            jsonMop.addProperty("variant", db.getVariant().getValue());
        if (db.getFace() != null)
            jsonMop.addProperty("facing", db.getFace().value());
        if (extraProperties.size() > 0) {
            // Add the extra properties that aren't covered by colour/variant/facing.
            for (IProperty prop : extraProperties) {
                String key = "prop_" + prop.getName();
                if (prop.getValueClass() == Boolean.class)
                    jsonMop.addProperty(key, Boolean.valueOf(state.getValue(prop).toString()));
                else if (prop.getValueClass() == Integer.class)
                    jsonMop.addProperty(key, Integer.valueOf(state.getValue(prop).toString()));
                else
                    jsonMop.addProperty(key, state.getValue(prop).toString());
            }
        }
        // Add the NBTTagCompound, if this is a tile entity.
        if (includeNBTData) {
            TileEntity tileentity = Minecraft.getMinecraft().world.getTileEntity(mop.getBlockPos());
            if (tileentity != null) {
                NBTTagCompound data = tileentity.getUpdateTag();
                if (data != null) {
                    // Turn data directly into json and add it to what we're already returning.
                    String jsonString = data.toString();
                    try {
                        JsonElement jelement = new JsonParser().parse(jsonString);
                        if (jelement != null)
                            jsonMop.add("NBTTagCompound", jelement);
                    } catch (JsonSyntaxException e) {
                    // Duff NBTTagCompound - ignore it.
                    }
                }
            }
        }
        jsonMop.addProperty("inRange", hitDist <= blockReach);
        jsonMop.addProperty("distance", hitDist);
    } else if (mop.typeOfHit == RayTraceResult.Type.ENTITY) {
        // Looking at an entity:
        Entity entity = mop.entityHit;
        if (entity != null) {
            jsonMop.addProperty("x", entity.posX);
            jsonMop.addProperty("y", entity.posY);
            jsonMop.addProperty("z", entity.posZ);
            jsonMop.addProperty("yaw", entity.rotationYaw);
            jsonMop.addProperty("pitch", entity.rotationPitch);
            String name = MinecraftTypeHelper.getUnlocalisedEntityName(entity);
            String hitType = "entity";
            if (entity instanceof EntityItem) {
                ItemStack is = ((EntityItem) entity).getEntityItem();
                DrawItem di = MinecraftTypeHelper.getDrawItemFromItemStack(is);
                if (di.getColour() != null)
                    jsonMop.addProperty("colour", di.getColour().value());
                if (di.getVariant() != null)
                    jsonMop.addProperty("variant", di.getVariant().getValue());
                jsonMop.addProperty("stackSize", is.getCount());
                name = di.getType();
                hitType = "item";
            }
            jsonMop.addProperty("type", name);
            jsonMop.addProperty("hitType", hitType);
        }
        jsonMop.addProperty("inRange", hitDist <= entityReach);
        jsonMop.addProperty("distance", hitDist);
    }
    json.add("LineOfSight", jsonMop);
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) JsonObject(com.google.gson.JsonObject) NBTTagString(net.minecraft.nbt.NBTTagString) Vec3d(net.minecraft.util.math.Vec3d) TileEntity(net.minecraft.tileentity.TileEntity) JsonSyntaxException(com.google.gson.JsonSyntaxException) IProperty(net.minecraft.block.properties.IProperty) JsonElement(com.google.gson.JsonElement) DrawItem(com.microsoft.Malmo.Schemas.DrawItem) DrawBlock(com.microsoft.Malmo.Schemas.DrawBlock) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) JsonParser(com.google.gson.JsonParser)

Example 48 with Vec3d

use of net.minecraft.util.math.Vec3d in project malmo by Microsoft.

the class ObservationFromRayImplementation method findEntity.

static RayTraceResult findEntity(Vec3d eyePos, Vec3d lookVec, double depth, RayTraceResult mop, boolean includeTiles) {
    // Based on code in EntityRenderer.getMouseOver()
    if (mop != null)
        depth = mop.hitVec.distanceTo(eyePos);
    Vec3d searchVec = eyePos.addVector(lookVec.xCoord * depth, lookVec.yCoord * depth, lookVec.zCoord * depth);
    Entity pointedEntity = null;
    Vec3d hitVec = null;
    Entity viewer = Minecraft.getMinecraft().player;
    List<?> list = Minecraft.getMinecraft().world.getEntitiesWithinAABBExcludingEntity(viewer, viewer.getEntityBoundingBox().addCoord(lookVec.xCoord * depth, lookVec.yCoord * depth, lookVec.zCoord * depth).expand(1.0, 1.0, 1.0));
    double distance = depth;
    for (int i = 0; i < list.size(); ++i) {
        Entity entity = (Entity) list.get(i);
        if (entity.canBeCollidedWith() || includeTiles) {
            float border = entity.getCollisionBorderSize();
            AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expand((double) border, (double) border, (double) border);
            RayTraceResult movingobjectposition = axisalignedbb.calculateIntercept(eyePos, searchVec);
            if (axisalignedbb.isVecInside(eyePos)) {
                // If entity is right inside our head?
                if (distance >= 0) {
                    pointedEntity = entity;
                    hitVec = (movingobjectposition == null) ? eyePos : mop.hitVec;
                    distance = 0.0D;
                }
            } else if (movingobjectposition != null) {
                double distToEnt = eyePos.distanceTo(movingobjectposition.hitVec);
                if (distToEnt < distance || distance == 0.0D) {
                    if (entity == entity.getRidingEntity() && !entity.canRiderInteract()) {
                        if (distance == 0.0D) {
                            pointedEntity = entity;
                            hitVec = movingobjectposition.hitVec;
                        }
                    } else {
                        pointedEntity = entity;
                        hitVec = movingobjectposition.hitVec;
                        distance = distToEnt;
                    }
                }
            }
        }
    }
    if (pointedEntity != null && (distance < depth || mop == null)) {
        RayTraceResult newMop = new RayTraceResult(pointedEntity, hitVec);
        return newMop;
    }
    return null;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d)

Example 49 with Vec3d

use of net.minecraft.util.math.Vec3d in project RFToolsDimensions by McJty.

the class GenericWorldProvider method getCloudColor.

@Override
@SideOnly(Side.CLIENT)
public Vec3d getCloudColor(float partialTicks) {
    getDimensionInformation();
    Vec3d cloudColor = super.getCloudColor(partialTicks);
    if (dimensionInformation == null || dimensionInformation.isPatreonBitSet(PatreonType.PATREON_KENNEY)) {
        return cloudColor;
    } else {
        float r = dimensionInformation.getSkyDescriptor().getCloudColorFactorR();
        float g = dimensionInformation.getSkyDescriptor().getCloudColorFactorG();
        float b = dimensionInformation.getSkyDescriptor().getCloudColorFactorB();
        return new Vec3d(cloudColor.x * r, cloudColor.y * g, cloudColor.z * b);
    }
}
Also used : Vec3d(net.minecraft.util.math.Vec3d) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 50 with Vec3d

use of net.minecraft.util.math.Vec3d in project MorePlanets by SteveKunG.

the class RenderInfectedElderGuardian method shouldRender.

@Override
public boolean shouldRender(EntityInfectedElderGuardian entity, ICamera camera, double camX, double camY, double camZ) {
    if (super.shouldRender(entity, camera, camX, camY, camZ)) {
        return true;
    } else {
        if (entity.hasTargetedEntity()) {
            EntityLivingBase entitylivingbase = entity.getTargetedEntity();
            if (entitylivingbase != null) {
                Vec3d vec3 = this.getPosition(entitylivingbase, entitylivingbase.height * 0.5D, 1.0F);
                Vec3d vec31 = this.getPosition(entity, entity.getEyeHeight(), 1.0F);
                if (camera.isBoundingBoxInFrustum(new AxisAlignedBB(vec31.x, vec31.y, vec31.z, vec3.x, vec3.y, vec3.z))) {
                    return true;
                }
            }
        }
        return false;
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Vec3d (net.minecraft.util.math.Vec3d)789 BlockPos (net.minecraft.util.math.BlockPos)204 Entity (net.minecraft.entity.Entity)118 EnumFacing (net.minecraft.util.EnumFacing)108 ItemStack (net.minecraft.item.ItemStack)100 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)97 RayTraceResult (net.minecraft.util.math.RayTraceResult)90 World (net.minecraft.world.World)90 EntityPlayer (net.minecraft.entity.player.EntityPlayer)88 IBlockState (net.minecraft.block.state.IBlockState)76 EntityLivingBase (net.minecraft.entity.EntityLivingBase)74 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)72 ResourceLocation (net.minecraft.util.ResourceLocation)68 ParticleBuilder (com.teamwizardry.librarianlib.features.particle.ParticleBuilder)59 InterpFadeInOut (com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut)59 TileEntity (net.minecraft.tileentity.TileEntity)42 Block (net.minecraft.block.Block)41 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)30 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)27 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)27