Search in sources :

Example 1 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project BetterStorage by copygirl.

the class ClientProxy method drawBlockHighlight.

@SubscribeEvent
public void drawBlockHighlight(DrawBlockHighlightEvent event) {
    EntityPlayer player = event.player;
    World world = player.worldObj;
    MovingObjectPosition target = WorldUtils.rayTrace(player, event.partialTicks);
    if ((target == null) || (target.typeOfHit != MovingObjectType.BLOCK))
        return;
    int x = target.blockX;
    int y = target.blockY;
    int z = target.blockZ;
    AxisAlignedBB box = null;
    Block block = world.getBlock(x, y, z);
    TileEntity tileEntity = world.getTileEntity(x, y, z);
    if (block instanceof TileArmorStand)
        box = getArmorStandHighlightBox(player, world, x, y, z, target.hitVec);
    else if (block == Blocks.iron_door)
        box = getIronDoorHightlightBox(player, world, x, y, z, target.hitVec, block);
    else if (tileEntity instanceof IHasAttachments)
        box = getAttachmentPointsHighlightBox(player, tileEntity, target);
    if (box == null)
        return;
    double xOff = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.partialTicks;
    double yOff = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.partialTicks;
    double zOff = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.partialTicks;
    box.offset(-xOff, -yOff, -zOff);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F);
    GL11.glLineWidth(2.0F);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDepthMask(false);
    RenderGlobal.drawOutlinedBoundingBox(box, -1);
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_BLEND);
    event.setCanceled(true);
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) TileArmorStand(net.mcft.copy.betterstorage.tile.stand.TileArmorStand) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) World(net.minecraft.world.World) IHasAttachments(net.mcft.copy.betterstorage.attachment.IHasAttachments) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 2 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project BetterStorage by copygirl.

the class TileEntityPresentRenderer method renderTileEntityAt.

public void renderTileEntityAt(TileEntityPresent present, double x, double y, double z, float partialTicks) {
    TextureManager texMan = Minecraft.getMinecraft().getTextureManager();
    GL11.glPushMatrix();
    GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    GL11.glTranslated(x + 0.5, y, z + 0.5);
    texMan.bindTexture(texMan.getResourceLocation(0));
    renderSome(present.colorInner, 1);
    renderSome(present.colorOuter, (present.skojanzaMode ? new int[] { 2, 3 } : new int[] { 2 }));
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDepthFunc(GL11.GL_EQUAL);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    texMan.bindTexture(Resources.texturePresentOverlay);
    model.render(1);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glDisable(GL11.GL_BLEND);
    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    if ((present.nameTag != null) && (present.getWorldObj() != null) && (player != null) && (player.getDistanceSq(present.xCoord + 0.5, present.yCoord + 0.5, present.zCoord + 0.5) < NAMETAG_RENDER_RANGE_SQ)) {
        MovingObjectPosition o = Minecraft.getMinecraft().objectMouseOver;
        renderNameTag(present.nameTag, player.getCommandSenderName().equalsIgnoreCase(present.nameTag), ((o.blockX == present.xCoord) && (o.blockY == present.yCoord) && (o.blockZ == present.zCoord)));
    }
    GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    GL11.glPopMatrix();
}
Also used : TextureManager(net.minecraft.client.renderer.texture.TextureManager) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 3 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project BetterStorage by copygirl.

the class WorldUtils method rayTrace.

// Misc functions
public static MovingObjectPosition rayTrace(EntityPlayer player, float partialTicks) {
    Attachments.playerLocal.set(player);
    double range = ((player.worldObj.isRemote) ? Minecraft.getMinecraft().playerController.getBlockReachDistance() : ((EntityPlayerMP) player).theItemInWorldManager.getBlockReachDistance());
    Vec3 start = Vec3.createVectorHelper(player.posX, player.posY + 1.62 - player.yOffset, player.posZ);
    Vec3 look = player.getLook(1.0F);
    Vec3 end = start.addVector(look.xCoord * range, look.yCoord * range, look.zCoord * range);
    MovingObjectPosition target = player.worldObj.rayTraceBlocks(start, end);
    Attachments.playerLocal.remove();
    return target;
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3)

Example 4 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method doRayTrace.

private RaytraceResult doRayTrace(LogisticsTileGenericPipe tileG, CoreMultiBlockPipe pipe, Vec3 origin, Vec3 direction) {
    if (tileG == null) {
        return null;
    }
    if (!LogisticsBlockGenericPipe.isValid(pipe)) {
        return null;
    }
    List<MovingObjectPosition> hits = new ArrayList<>();
    List<AxisAlignedBB> boxes = new ArrayList<>();
    pipe.addCollisionBoxesToList(boxes, null);
    while (hits.size() < boxes.size()) {
        hits.add(null);
    }
    for (int i = 0; i < boxes.size(); i++) {
        AxisAlignedBB bb = boxes.get(i);
        setBlockBoundsFromAbsolut(bb, tileG);
        hits.set(i, super.collisionRayTrace(tileG.getWorldObj(), tileG.xCoord, tileG.yCoord, tileG.zCoord, origin, direction));
    }
    double minLengthSquared = Double.POSITIVE_INFINITY;
    int minIndex = -1;
    for (int i = 0; i < hits.size(); i++) {
        MovingObjectPosition hit = hits.get(i);
        if (hit == null) {
            continue;
        }
        double lengthSquared = hit.hitVec.squareDistanceTo(origin);
        if (lengthSquared < minLengthSquared) {
            minLengthSquared = lengthSquared;
            minIndex = i;
        }
    }
    // reset bounds
    setBlockBounds(0, 0, 0, 1, 1, 1);
    if (minIndex == -1) {
        return null;
    } else {
        return new RaytraceResult(Part.Pipe, hits.get(minIndex), //*
        pipe.getCompleteBox(), /*/
					boxes.get(minIndex).getOffsetBoundingBox(-tileG.xCoord, -tileG.yCoord, -tileG.zCoord)
					//*/
        ForgeDirection.UNKNOWN);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) ArrayList(java.util.ArrayList)

Example 5 with MovingObjectPosition

use of net.minecraft.util.MovingObjectPosition in project LogisticsPipes by RS485.

the class LogisticsBlockGenericPipe method collisionRayTrace.

@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 origin, Vec3 direction) {
    TileEntity tile = world.getTileEntity(x, y, z);
    if (tile instanceof LogisticsTileGenericPipe && ((LogisticsTileGenericPipe) tile).pipe instanceof PipeBlockRequestTable) {
        setBlockBoundsBasedOnState(world, x, y, z);
        origin = origin.addVector((-x), (-y), (-z));
        direction = direction.addVector((-x), (-y), (-z));
        this.setBlockBounds(0, 0, 0, 1, 1, 1);
        Vec3 vec32 = origin.getIntermediateWithXValue(direction, minX);
        Vec3 vec33 = origin.getIntermediateWithXValue(direction, maxX);
        Vec3 vec34 = origin.getIntermediateWithYValue(direction, minY);
        Vec3 vec35 = origin.getIntermediateWithYValue(direction, maxY);
        Vec3 vec36 = origin.getIntermediateWithZValue(direction, minZ);
        Vec3 vec37 = origin.getIntermediateWithZValue(direction, maxZ);
        if (!isVecInsideYZBounds(vec32)) {
            vec32 = null;
        }
        if (!isVecInsideYZBounds(vec33)) {
            vec33 = null;
        }
        if (!isVecInsideXZBounds(vec34)) {
            vec34 = null;
        }
        if (!isVecInsideXZBounds(vec35)) {
            vec35 = null;
        }
        if (!isVecInsideXYBounds(vec36)) {
            vec36 = null;
        }
        if (!isVecInsideXYBounds(vec37)) {
            vec37 = null;
        }
        Vec3 vec38 = null;
        if (vec32 != null && (vec38 == null || origin.squareDistanceTo(vec32) < origin.squareDistanceTo(vec38))) {
            vec38 = vec32;
        }
        if (vec33 != null && (vec38 == null || origin.squareDistanceTo(vec33) < origin.squareDistanceTo(vec38))) {
            vec38 = vec33;
        }
        if (vec34 != null && (vec38 == null || origin.squareDistanceTo(vec34) < origin.squareDistanceTo(vec38))) {
            vec38 = vec34;
        }
        if (vec35 != null && (vec38 == null || origin.squareDistanceTo(vec35) < origin.squareDistanceTo(vec38))) {
            vec38 = vec35;
        }
        if (vec36 != null && (vec38 == null || origin.squareDistanceTo(vec36) < origin.squareDistanceTo(vec38))) {
            vec38 = vec36;
        }
        if (vec37 != null && (vec38 == null || origin.squareDistanceTo(vec37) < origin.squareDistanceTo(vec38))) {
            vec38 = vec37;
        }
        if (vec38 == null) {
            return null;
        } else {
            byte b0 = -1;
            if (vec38 == vec32) {
                b0 = 4;
            }
            if (vec38 == vec33) {
                b0 = 5;
            }
            if (vec38 == vec34) {
                b0 = 0;
            }
            if (vec38 == vec35) {
                b0 = 1;
            }
            if (vec38 == vec36) {
                b0 = 2;
            }
            if (vec38 == vec37) {
                b0 = 3;
            }
            return new MovingObjectPosition(x, y, z, b0, vec38.addVector(x, y, z));
        }
    }
    RaytraceResult raytraceResult = doRayTrace(world, x, y, z, origin, direction);
    if (raytraceResult == null) {
        return null;
    } else {
        return raytraceResult.movingObjectPosition;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PipeBlockRequestTable(logisticspipes.pipes.PipeBlockRequestTable) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) Vec3(net.minecraft.util.Vec3)

Aggregations

MovingObjectPosition (net.minecraft.util.MovingObjectPosition)60 Vec3 (net.minecraft.util.Vec3)19 Entity (net.minecraft.entity.Entity)17 EntityPlayer (net.minecraft.entity.player.EntityPlayer)17 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)17 ItemStack (net.minecraft.item.ItemStack)16 TileEntity (net.minecraft.tileentity.TileEntity)16 ArrayList (java.util.ArrayList)11 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)10 Block (net.minecraft.block.Block)8 EntityLivingBase (net.minecraft.entity.EntityLivingBase)7 AMVector3 (am2.api.math.AMVector3)5 World (net.minecraft.world.World)5 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)4 List (java.util.List)4 SpellCastResult (am2.api.spell.enums.SpellCastResult)3 ParticleApproachPoint (am2.particles.ParticleApproachPoint)3 IBlockState (net.minecraft.block.state.IBlockState)3 AMParticle (am2.particles.AMParticle)2 PacketPlayerItem (com.builtbroken.mc.core.network.packet.PacketPlayerItem)2