Search in sources :

Example 26 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project Railcraft by Railcraft.

the class ItemFluidContainer method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    RayTraceResult mop = rayTrace(world, player, false);
    //noinspection ConstantConditions
    if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) {
        BlockPos pos = mop.getBlockPos();
        if (!world.isBlockModifiable(player, pos))
            return new ActionResult<>(EnumActionResult.FAIL, stack);
        pos = pos.offset(mop.sideHit);
        if (!player.canPlayerEdit(pos, mop.sideHit, stack))
            return new ActionResult<>(EnumActionResult.FAIL, stack);
        if (tryPlaceContainedLiquid(world, pos) && !player.capabilities.isCreativeMode) {
            ItemStack empty = getContainerItem(stack);
            if (InvTools.isEmpty(empty)) {
                empty = stack.copy();
                empty.stackSize = 0;
            }
            return new ActionResult<>(EnumActionResult.SUCCESS, empty);
        }
    }
    return new ActionResult<>(EnumActionResult.PASS, stack);
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 27 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project Guide-API by TeamAmeriFrance.

the class EventHandler method renderOverlay.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Pre event) {
    if (event.getType() != RenderGameOverlayEvent.ElementType.CROSSHAIRS)
        return;
    RayTraceResult rayTrace = Minecraft.getMinecraft().objectMouseOver;
    if (rayTrace == null || rayTrace.typeOfHit != RayTraceResult.Type.BLOCK)
        return;
    EntityPlayer player = Minecraft.getMinecraft().player;
    World world = Minecraft.getMinecraft().world;
    ItemStack held = ItemStack.EMPTY;
    Book book = null;
    for (EnumHand hand : EnumHand.values()) {
        ItemStack heldStack = player.getHeldItem(hand);
        if (heldStack.getItem() instanceof IGuideItem) {
            held = heldStack;
            book = ((IGuideItem) heldStack.getItem()).getBook(heldStack);
            break;
        }
    }
    if (book == null)
        return;
    IBlockState state = world.getBlockState(rayTrace.getBlockPos());
    String linkedEntry = null;
    if (state.getBlock() instanceof IGuideLinked) {
        IGuideLinked linked = (IGuideLinked) state.getBlock();
        ResourceLocation entryKey = linked.getLinkedEntry(world, rayTrace.getBlockPos(), player, held);
        if (entryKey != null) {
            for (CategoryAbstract category : book.getCategoryList()) {
                if (category.entries.containsKey(entryKey)) {
                    linkedEntry = category.getEntry(entryKey).getLocalizedName();
                    break;
                }
            }
        }
    }
    if (!Strings.isNullOrEmpty(linkedEntry)) {
        FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
        ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
        int drawX = scaledResolution.getScaledWidth() / 2 + 10;
        int drawY = scaledResolution.getScaledHeight() / 2 - 8;
        Minecraft.getMinecraft().getRenderItem().renderItemIntoGUI(held, drawX, drawY);
        drawY -= 2;
        drawX += 20;
        fontRenderer.drawStringWithShadow(TextFormatting.WHITE + linkedEntry, drawX, drawY, 0);
        fontRenderer.drawStringWithShadow(TextFormatting.WHITE.toString() + TextFormatting.ITALIC.toString() + TextHelper.localize("text.linked.open"), drawX, drawY + 12, 0);
    }
    if (state.getBlock() instanceof IInfoRenderer.Block) {
        IInfoRenderer infoRenderer = ((IInfoRenderer.Block) state.getBlock()).getInfoRenderer(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
        if (book == ((IInfoRenderer.Block) state.getBlock()).getBook() && infoRenderer != null)
            infoRenderer.drawInformation(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
    }
    Multimap<Class<? extends Block>, IInfoRenderer> bookRenderers = GuideAPI.getInfoRenderers().get(book);
    if (bookRenderers == null)
        return;
    Collection<IInfoRenderer> renderers = bookRenderers.get(state.getBlock().getClass());
    for (IInfoRenderer renderer : renderers) renderer.drawInformation(book, world, rayTrace.getBlockPos(), state, rayTrace, player);
}
Also used : IGuideLinked(amerifrance.guideapi.api.IGuideLinked) IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) IInfoRenderer(amerifrance.guideapi.api.IInfoRenderer) ScaledResolution(net.minecraft.client.gui.ScaledResolution) CategoryAbstract(amerifrance.guideapi.api.impl.abstraction.CategoryAbstract) Book(amerifrance.guideapi.api.impl.Book) EnumHand(net.minecraft.util.EnumHand) ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) IGuideItem(amerifrance.guideapi.api.IGuideItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 28 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class CallRunnerClient method onOrientCamera.

public static void onOrientCamera(EntityRenderer renderer, float partialTicks) {
    Entity entity = renderer.mc.getRenderViewEntity();
    BlockPos playerPos = new BlockPos(entity);
    PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(entity.worldObj, playerPos);
    if (wrapper != null) {
        Vector playerPosNew = new Vector(entity.posX, entity.posY, entity.posZ);
        RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.lToWTransform, playerPosNew);
        entity.posX = entity.prevPosX = entity.lastTickPosX = playerPosNew.X;
        entity.posY = entity.prevPosY = entity.lastTickPosY = playerPosNew.Y;
        entity.posZ = entity.prevPosZ = entity.lastTickPosZ = playerPosNew.Z;
    }
    Vector eyeVector = new Vector(0, entity.getEyeHeight(), 0);
    if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
        eyeVector.Y += .7D;
    }
    double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double) partialTicks;
    double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double) partialTicks;
    double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) partialTicks;
    PhysicsWrapperEntity fixedOnto = ValkyrienWarfareMod.physicsManager.getShipFixedOnto(entity);
    //Probably overkill, but this should 100% fix the crash in issue #78
    if (fixedOnto != null && fixedOnto.wrapping != null && fixedOnto.wrapping.renderer != null && fixedOnto.wrapping.renderer.offsetPos != null) {
        Quaternion orientationQuat = fixedOnto.wrapping.renderer.getSmoothRotationQuat(partialTicks);
        double[] radians = orientationQuat.toRadians();
        float moddedPitch = (float) Math.toDegrees(radians[0]);
        float moddedYaw = (float) Math.toDegrees(radians[1]);
        float moddedRoll = (float) Math.toDegrees(radians[2]);
        double[] orientationMatrix = RotationMatrices.getRotationMatrix(moddedPitch, moddedYaw, moddedRoll);
        RotationMatrices.applyTransform(orientationMatrix, eyeVector);
        Vector playerPosition = new Vector(fixedOnto.wrapping.getLocalPositionForEntity(entity));
        RotationMatrices.applyTransform(fixedOnto.wrapping.coordTransform.RlToWTransform, playerPosition);
        d0 = playerPosition.X;
        d1 = playerPosition.Y;
        d2 = playerPosition.Z;
    //			entity.posX = entity.prevPosX = entity.lastTickPosX = d0;
    //			entity.posY = entity.prevPosY = entity.lastTickPosY = d1;
    //			entity.posZ = entity.prevPosZ = entity.lastTickPosZ = d2;
    }
    d0 += eyeVector.X;
    d1 += eyeVector.Y;
    d2 += eyeVector.Z;
    if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
        if (!renderer.mc.gameSettings.debugCamEnable) {
            //VW code starts here
            if (fixedOnto != null) {
                Vector playerPosInLocal = new Vector(fixedOnto.wrapping.getLocalPositionForEntity(entity));
                playerPosInLocal.subtract(.5D, .6875, .5);
                playerPosInLocal.roundToWhole();
                BlockPos bedPos = new BlockPos(playerPosInLocal.X, playerPosInLocal.Y, playerPosInLocal.Z);
                IBlockState state = renderer.mc.theWorld.getBlockState(bedPos);
                Block block = state.getBlock();
                float angleYaw = 0;
                if (block != null && block.isBed(state, entity.worldObj, bedPos, entity)) {
                    angleYaw = (float) (block.getBedDirection(state, entity.worldObj, bedPos).getHorizontalIndex() * 90);
                    angleYaw += 180;
                }
                entity.rotationYaw = entity.prevRotationYaw = angleYaw;
                entity.rotationPitch = entity.prevRotationPitch = 0;
            } else {
                BlockPos blockpos = new BlockPos(entity);
                IBlockState iblockstate = renderer.mc.theWorld.getBlockState(blockpos);
                net.minecraftforge.client.ForgeHooksClient.orientBedCamera(renderer.mc.theWorld, blockpos, iblockstate, entity);
                GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, -1.0F, 0.0F);
                GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, -1.0F, 0.0F, 0.0F);
            }
        }
    } else if (renderer.mc.gameSettings.thirdPersonView > 0) {
        double d3 = (double) (renderer.thirdPersonDistancePrev + (4.0F - renderer.thirdPersonDistancePrev) * partialTicks);
        if (ClientPilotingManager.isPlayerPilotingShip()) {
            //TODO: Make this number scale with the Ship
            d3 = 15D;
        }
        if (renderer.mc.gameSettings.debugCamEnable) {
            GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
        } else {
            float f1 = entity.rotationYaw;
            float f2 = entity.rotationPitch;
            if (renderer.mc.gameSettings.thirdPersonView == 2) {
                f2 += 180.0F;
            }
            double d4 = (double) (-MathHelper.sin(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F)) * d3;
            double d5 = (double) (MathHelper.cos(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F)) * d3;
            double d6 = (double) (-MathHelper.sin(f2 * 0.017453292F)) * d3;
            for (int i = 0; i < 8; ++i) {
                float f3 = (float) ((i & 1) * 2 - 1);
                float f4 = (float) ((i >> 1 & 1) * 2 - 1);
                float f5 = (float) ((i >> 2 & 1) * 2 - 1);
                f3 = f3 * 0.1F;
                f4 = f4 * 0.1F;
                f5 = f5 * 0.1F;
                RayTraceResult raytraceresult = CallRunnerClient.rayTraceBlocksIgnoreShip(Minecraft.getMinecraft().theWorld, new Vec3d(d0 + (double) f3, d1 + (double) f4, d2 + (double) f5), new Vec3d(d0 - d4 + (double) f3 + (double) f5, d1 - d6 + (double) f4, d2 - d5 + (double) f5), false, false, false, ClientPilotingManager.getPilotedWrapperEntity());
                if (raytraceresult != null) {
                    double d7 = raytraceresult.hitVec.distanceTo(new Vec3d(d0, d1, d2));
                    if (d7 < d3) {
                        d3 = d7;
                    }
                }
            }
            if (renderer.mc.gameSettings.thirdPersonView == 2) {
                GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
            }
            GlStateManager.rotate(entity.rotationPitch - f2, 1.0F, 0.0F, 0.0F);
            GlStateManager.rotate(entity.rotationYaw - f1, 0.0F, 1.0F, 0.0F);
            GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
            GlStateManager.rotate(f1 - entity.rotationYaw, 0.0F, 1.0F, 0.0F);
            GlStateManager.rotate(f2 - entity.rotationPitch, 1.0F, 0.0F, 0.0F);
        }
    } else {
        GlStateManager.translate(0.0F, 0.0F, 0.05F);
    }
    if (!renderer.mc.gameSettings.debugCamEnable) {
        float yaw = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F;
        float pitch = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks;
        float roll = 0.0F;
        if (entity instanceof EntityAnimal) {
            EntityAnimal entityanimal = (EntityAnimal) entity;
            yaw = entityanimal.prevRotationYawHead + (entityanimal.rotationYawHead - entityanimal.prevRotationYawHead) * partialTicks + 180.0F;
        }
        IBlockState state = ActiveRenderInfo.getBlockStateAtEntityViewpoint(renderer.mc.theWorld, entity, partialTicks);
        net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup event = new net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup(renderer, entity, state, partialTicks, yaw, pitch, roll);
        net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
        GlStateManager.rotate(event.getRoll(), 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(event.getPitch(), 1.0F, 0.0F, 0.0F);
        GlStateManager.rotate(event.getYaw(), 0.0F, 1.0F, 0.0F);
    }
    if (fixedOnto != null && fixedOnto.wrapping != null && fixedOnto.wrapping.renderer != null && fixedOnto.wrapping.renderer.offsetPos != null) {
        Quaternion orientationQuat = fixedOnto.wrapping.renderer.getSmoothRotationQuat(partialTicks);
        double[] radians = orientationQuat.toRadians();
        float moddedPitch = (float) Math.toDegrees(radians[0]);
        float moddedYaw = (float) Math.toDegrees(radians[1]);
        float moddedRoll = (float) Math.toDegrees(radians[2]);
        GlStateManager.rotate(-moddedRoll, 0.0F, 0.0F, 1.0F);
        GlStateManager.rotate(-moddedYaw, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(-moddedPitch, 1.0F, 0.0F, 0.0F);
    }
    GlStateManager.translate(-eyeVector.X, -eyeVector.Y, -eyeVector.Z);
    d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double) partialTicks + eyeVector.X;
    d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double) partialTicks + eyeVector.Y;
    d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double) partialTicks + eyeVector.Z;
    renderer.cloudFog = renderer.mc.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks);
}
Also used : PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) Quaternion(ValkyrienWarfareBase.Math.Quaternion) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) EnumSkyBlock(net.minecraft.world.EnumSkyBlock) BlockPos(net.minecraft.util.math.BlockPos) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) Vector(ValkyrienWarfareBase.API.Vector)

Example 29 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project Witchworks by Um-Mitternacht.

the class RayTraceHelper method rayTraceResult.

public static RayTraceResult rayTraceResult(Entity source, Vec3d vec3, boolean includeEntities, boolean excludeSource) {
    double d0 = source.posX;
    double d1 = source.posY;
    double d2 = source.posZ;
    World world = source.world;
    Vec3d vec3d = new Vec3d(d0, d1, d2);
    Vec3d forward = vec3d.add(vec3);
    RayTraceResult raytraceresult = world.rayTraceBlocks(vec3d, forward, false, true, false);
    if (includeEntities) {
        if (raytraceresult != null) {
            forward = new Vec3d(raytraceresult.hitVec.xCoord, raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord);
        }
        Entity entity = null;
        List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(source, source.getEntityBoundingBox().addCoord(vec3.xCoord, vec3.yCoord, vec3.zCoord).expandXyz(1.0D));
        double d6 = 0.0D;
        for (Entity ent : list) {
            if (ent.canBeCollidedWith() && (excludeSource || !ent.isEntityEqual(source)) && !ent.noClip) {
                AxisAlignedBB axisalignedbb = ent.getEntityBoundingBox().expandXyz(0.30000001192092896D);
                RayTraceResult raytraceresult1 = axisalignedbb.calculateIntercept(vec3d, forward);
                if (raytraceresult1 != null) {
                    double d7 = vec3d.squareDistanceTo(raytraceresult1.hitVec);
                    if (d7 < d6 || d6 == 0.0D) {
                        entity = ent;
                        d6 = d7;
                    }
                }
            }
        }
        if (entity != null) {
            raytraceresult = new RayTraceResult(entity);
        }
    }
    return raytraceresult;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d)

Example 30 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ItemExplosiveArrow method createArrow.

@Override
public EntityArrow createArrow(World worldIn, ItemStack stack, EntityLivingBase shooter) {
    EntityTippedArrow entitytippedarrow = new EntityTippedArrow(worldIn, shooter) {

        private boolean doExpl = true;

        @Override
        public void onUpdate() {
            super.onUpdate();
        }

        @Override
        public boolean isImmuneToExplosions() {
            return true;
        }

        @Override
        protected void onHit(RayTraceResult raytraceResultIn) {
            super.onHit(raytraceResultIn);
            worldObj.createExplosion(this, posX, posY, posZ, 20F, true);
            kill();
        }
    };
    entitytippedarrow.setPotionEffect(stack);
    return entitytippedarrow;
}
Also used : EntityTippedArrow(net.minecraft.entity.projectile.EntityTippedArrow) RayTraceResult(net.minecraft.util.math.RayTraceResult)

Aggregations

RayTraceResult (net.minecraft.util.math.RayTraceResult)32 ItemStack (net.minecraft.item.ItemStack)16 IBlockState (net.minecraft.block.state.IBlockState)12 Vec3d (net.minecraft.util.math.Vec3d)12 Entity (net.minecraft.entity.Entity)11 BlockPos (net.minecraft.util.math.BlockPos)11 TileEntity (net.minecraft.tileentity.TileEntity)9 Block (net.minecraft.block.Block)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 World (net.minecraft.world.World)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 EntityLivingBase (net.minecraft.entity.EntityLivingBase)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)4 ArrayList (java.util.ArrayList)4 Vector (ValkyrienWarfareBase.API.Vector)2 WorldPhysObjectManager (ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager)2 ChemthrowerEffect_Potion (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 EntityArmorStand (net.minecraft.entity.item.EntityArmorStand)2