Search in sources :

Example 21 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project VoodooCraft by Mod-DevCafeTeam.

the class HexSuffocate method activeUse.

@Override
public ItemStack activeUse(ItemStack stackIn, World world, EntityPlayer player, EnumHand hand, int strength, @Nullable EntityLivingBase target) {
    if (!world.isRemote) {
        RayTraceResult result = Minecraft.getMinecraft().objectMouseOver;
        Entity e = result.entityHit;
        if (e instanceof EntityPlayerMP) {
            EntityPlayerMP p = (EntityPlayerMP) e;
            if (!p.capabilities.isCreativeMode) {
                for (int i = 0; i < p.getMaxHealth(); i++) {
                    int dif = world.getDifficulty().getDifficultyId();
                    p.setHealth(p.getHealth() - dif);
                    p.performHurtAnimation();
                }
            }
        }
    }
    return super.activeUse(stackIn, world, player, hand, strength, target);
}
Also used : Entity(net.minecraft.entity.Entity) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 22 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project OpenModularTurrets by OpenModularTurretsTeam.

the class TurretHeadUtil method canTurretSeeTarget.

public static boolean canTurretSeeTarget(TurretHead turret, EntityLivingBase target) {
    Vec3d traceStart = new Vec3d(turret.getPos().getX() + 0.5F, turret.getPos().getY() + 0.5F, turret.getPos().getZ() + 0.5F);
    if (ModCompatibility.ValkyrienWarfareLoaded) {
        Entity shipEntity = ValkyrienWarfareHelper.getShipManagingBlock(turret.getWorld(), turret.getPos());
        //Then the turret must be in Ship Space
        if (shipEntity != null) {
            traceStart = ValkyrienWarfareHelper.getVec3InWorldSpaceFromShipSpace(shipEntity, traceStart);
        }
    }
    Vec3d traceEnd = new Vec3d(target.posX, target.posY + target.getEyeHeight(), target.posZ);
    Vec3d vecDelta = new Vec3d(traceEnd.xCoord - traceStart.xCoord, traceEnd.yCoord - traceStart.yCoord, traceEnd.zCoord - traceStart.zCoord);
    // Normalize vector to the largest delta axis
    vecDelta = vecDelta.normalize();
    // Limit how many non solid block a turret can see through
    for (int i = 0; i < 10; i++) {
        // Offset start position toward the target to prevent self collision
        traceStart = traceStart.add(vecDelta);
        RayTraceResult traced = turret.getWorld().rayTraceBlocks(traceStart, traceEnd);
        if (traced != null && traced.typeOfHit == RayTraceResult.Type.BLOCK) {
            IBlockState hitBlock = turret.getWorld().getBlockState(traced.getBlockPos());
            // tracing
            if ((traced.getBlockPos().equals(turret.getPos())) || (!hitBlock.getMaterial().isSolid() && MathTools.abs_max(MathTools.abs_max(traceStart.xCoord - traceEnd.xCoord, traceStart.yCoord - traceEnd.yCoord), traceStart.zCoord - traceEnd.zCoord) > 1)) {
                // Start at new position and continue
                traceStart = traced.hitVec;
                continue;
            }
        }
        EntityLivingBase targeted = traced == null ? target : null;
        return targeted != null && targeted.equals(target);
    }
    // If all above failed, the target cannot be seen
    return false;
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Vec3d(net.minecraft.util.math.Vec3d)

Example 23 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project SecurityCraft by Geforce132.

the class TileEntitySCTE method update.

@Override
public void update() {
    if (intersectsEntities) {
        int i = this.pos.getX();
        int j = this.pos.getY();
        int k = this.pos.getZ();
        AxisAlignedBB axisalignedbb = (new AxisAlignedBB(i, j, k, i + 1, j + 1, k + 1));
        List<?> list = this.worldObj.getEntitiesWithinAABB(Entity.class, axisalignedbb);
        Iterator<?> iterator = list.iterator();
        Entity entity;
        while (iterator.hasNext()) {
            entity = (Entity) iterator.next();
            entityIntersecting(entity);
        }
    }
    if (viewActivated) {
        if (blockPlaceCooldown > 0) {
            blockPlaceCooldown--;
            return;
        }
        if (viewCooldown > 0) {
            viewCooldown--;
            return;
        }
        int i = this.pos.getX();
        int j = this.pos.getY();
        int k = this.pos.getZ();
        AxisAlignedBB axisalignedbb = (new AxisAlignedBB(i, j, k, (i), (j), (k)).expand(5, 5, 5));
        List<?> list = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
        Iterator<?> iterator = list.iterator();
        EntityLivingBase entity;
        while (iterator.hasNext()) {
            entity = (EntityLivingBase) iterator.next();
            double eyeHeight = entity.getEyeHeight();
            boolean isPlayer = (entity instanceof EntityPlayer);
            Vec3d lookVec = new Vec3d((entity.posX + (entity.getLookVec().xCoord * 5)), ((eyeHeight + entity.posY) + (entity.getLookVec().yCoord * 5)), (entity.posZ + (entity.getLookVec().zCoord * 5)));
            RayTraceResult mop = getWorld().rayTraceBlocks(new Vec3d(entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ), lookVec);
            if (mop != null && mop.typeOfHit == Type.BLOCK) {
                if (mop.getBlockPos().getX() == getPos().getX() && mop.getBlockPos().getY() == getPos().getY() && mop.getBlockPos().getZ() == getPos().getZ()) {
                    if ((isPlayer && activatedOnlyByPlayer()) || !activatedOnlyByPlayer()) {
                        entityViewed(entity);
                        viewCooldown = getViewCooldown();
                    }
                }
            }
        }
    }
    if (attacks) {
        if (attackCooldown < getTicksBetweenAttacks()) {
            attackCooldown++;
            return;
        }
        if (canAttack()) {
            int i = pos.getX();
            int j = pos.getY();
            int k = pos.getZ();
            AxisAlignedBB axisalignedbb = new AxisAlignedBB(i, j, k, i + 1, j + 1, k + 1).expand(getAttackRange(), getAttackRange(), getAttackRange());
            List<?> list = this.worldObj.getEntitiesWithinAABB(entityTypeToAttack(), axisalignedbb);
            Iterator<?> iterator = list.iterator();
            if (!worldObj.isRemote) {
                boolean attacked = false;
                while (iterator.hasNext()) {
                    Entity mobToAttack = (Entity) iterator.next();
                    if (mobToAttack == null || mobToAttack instanceof EntityItem || !shouldAttackEntityType(mobToAttack)) {
                        continue;
                    }
                    if (attackEntity(mobToAttack)) {
                        attacked = true;
                    }
                }
                if (attacked || shouldRefreshAttackCooldown()) {
                    attackCooldown = 0;
                }
                if (attacked || shouldSyncToClient()) {
                    sync();
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Vec3d(net.minecraft.util.math.Vec3d) EntityItem(net.minecraft.entity.item.EntityItem)

Example 24 with RayTraceResult

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

the class TESRSignals method renderTileEntityAt.

@Override
public void renderTileEntityAt(T tile, double x, double y, double z, float partialTicks, int destroyStage) {
    if (tile instanceof IControllerTile) {
        if (EffectManager.instance.isGoggleAuraActive(ItemGoggles.GoggleAura.TUNING)) {
            renderPairs(tile, x, y, z, partialTicks, ((IControllerTile) tile).getController(), ColorProfile.RAINBOW);
        } else if (EffectManager.instance.isGoggleAuraActive(ItemGoggles.GoggleAura.SIGNALLING)) {
            renderPairs(tile, x, y, z, partialTicks, ((IControllerTile) tile).getController(), ColorProfile.ASPECT);
        }
    }
    if (tile instanceof ISignalBlockTile) {
        if (EffectManager.instance.isGoggleAuraActive(ItemGoggles.GoggleAura.SURVEYING)) {
            renderPairs(tile, x, y, z, partialTicks, ((ISignalBlockTile) tile).getSignalBlock(), ColorProfile.RAINBOW);
        } else if (EffectManager.instance.isGoggleAuraActive(ItemGoggles.GoggleAura.SIGNALLING)) {
            renderPairs(tile, x, y, z, partialTicks, ((ISignalBlockTile) tile).getSignalBlock(), ColorProfile.BLUE);
        }
    }
    AbstractPair pair = null;
    if (tile instanceof IReceiverTile) {
        pair = ((IReceiverTile) tile).getReceiver();
    } else if (tile instanceof IControllerTile) {
        pair = ((IControllerTile) tile).getController();
    } else if (tile instanceof ISignalBlockTile) {
        pair = ((ISignalBlockTile) tile).getSignalBlock();
    }
    if (pair != null) {
        String name = pair.getName();
        if (name != null) {
            Entity player = Minecraft.getMinecraft().getRenderManager().renderViewEntity;
            if (player != null) {
                final float viewDist = 8f;
                double dist = player.getDistanceSq(tile.getPos());
                if (dist <= (double) (viewDist * viewDist)) {
                    RayTraceResult mop = player.rayTrace(8, partialTicks);
                    if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK && player.worldObj.getTileEntity(mop.getBlockPos()) == tile) {
                        RenderTools.renderString(name, x + 0.5, y + 1.5, z + 0.5);
                    }
                }
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult)

Example 25 with RayTraceResult

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

the class ThaumcraftApiHelper method rayTraceIgnoringSource.

//    private static HashMap<Integer, AspectList> allAspects= new HashMap<Integer, AspectList>();
//    private static HashMap<Integer, AspectList> allCompoundAspects= new HashMap<Integer, AspectList>();
//    
//    public static AspectList getAllAspects(int amount) {
//    	if (allAspects.get(amount)==null) {
//    		AspectList al = new AspectList();
//    		for (Aspect aspect:Aspect.aspects.values()) {
//    			al.add(aspect, amount);
//    		}
//    		allAspects.put(amount, al);
//    	} 
//    	return allAspects.get(amount);
//    }
//    
//    public static AspectList getAllCompoundAspects(int amount) {
//    	if (allCompoundAspects.get(amount)==null) {
//    		AspectList al = new AspectList();
//    		for (Aspect aspect:Aspect.getCompoundAspects()) {
//    			al.add(aspect, amount);
//    		}
//    		allCompoundAspects.put(amount, al);
//    	} 
//    	return allCompoundAspects.get(amount);
//    }
public static RayTraceResult rayTraceIgnoringSource(World world, Vec3d v1, Vec3d v2, boolean bool1, boolean bool2, boolean bool3) {
    if (!Double.isNaN(v1.xCoord) && !Double.isNaN(v1.yCoord) && !Double.isNaN(v1.zCoord)) {
        if (!Double.isNaN(v2.xCoord) && !Double.isNaN(v2.yCoord) && !Double.isNaN(v2.zCoord)) {
            int i = MathHelper.floor_double(v2.xCoord);
            int j = MathHelper.floor_double(v2.yCoord);
            int k = MathHelper.floor_double(v2.zCoord);
            int l = MathHelper.floor_double(v1.xCoord);
            int i1 = MathHelper.floor_double(v1.yCoord);
            int j1 = MathHelper.floor_double(v1.zCoord);
            IBlockState block = world.getBlockState(new BlockPos(l, i1, j1));
            RayTraceResult movingobjectposition2 = null;
            int k1 = 200;
            while (k1-- >= 0) {
                if (Double.isNaN(v1.xCoord) || Double.isNaN(v1.yCoord) || Double.isNaN(v1.zCoord)) {
                    return null;
                }
                if (l == i && i1 == j && j1 == k) {
                    continue;
                }
                boolean flag6 = true;
                boolean flag3 = true;
                boolean flag4 = true;
                double d0 = 999.0D;
                double d1 = 999.0D;
                double d2 = 999.0D;
                if (i > l) {
                    d0 = (double) l + 1.0D;
                } else if (i < l) {
                    d0 = (double) l + 0.0D;
                } else {
                    flag6 = false;
                }
                if (j > i1) {
                    d1 = (double) i1 + 1.0D;
                } else if (j < i1) {
                    d1 = (double) i1 + 0.0D;
                } else {
                    flag3 = false;
                }
                if (k > j1) {
                    d2 = (double) j1 + 1.0D;
                } else if (k < j1) {
                    d2 = (double) j1 + 0.0D;
                } else {
                    flag4 = false;
                }
                double d3 = 999.0D;
                double d4 = 999.0D;
                double d5 = 999.0D;
                double d6 = v2.xCoord - v1.xCoord;
                double d7 = v2.yCoord - v1.yCoord;
                double d8 = v2.zCoord - v1.zCoord;
                if (flag6) {
                    d3 = (d0 - v1.xCoord) / d6;
                }
                if (flag3) {
                    d4 = (d1 - v1.yCoord) / d7;
                }
                if (flag4) {
                    d5 = (d2 - v1.zCoord) / d8;
                }
                if (d3 == -0.0D) {
                    d3 = -1.0E-4D;
                }
                if (d4 == -0.0D) {
                    d4 = -1.0E-4D;
                }
                if (d5 == -0.0D) {
                    d5 = -1.0E-4D;
                }
                EnumFacing enumfacing;
                if (d3 < d4 && d3 < d5) {
                    enumfacing = i > l ? EnumFacing.WEST : EnumFacing.EAST;
                    v1 = new Vec3d(d0, v1.yCoord + d7 * d3, v1.zCoord + d8 * d3);
                } else if (d4 < d5) {
                    enumfacing = j > i1 ? EnumFacing.DOWN : EnumFacing.UP;
                    v1 = new Vec3d(v1.xCoord + d6 * d4, d1, v1.zCoord + d8 * d4);
                } else {
                    enumfacing = k > j1 ? EnumFacing.NORTH : EnumFacing.SOUTH;
                    v1 = new Vec3d(v1.xCoord + d6 * d5, v1.yCoord + d7 * d5, d2);
                }
                l = MathHelper.floor_double(v1.xCoord) - (enumfacing == EnumFacing.EAST ? 1 : 0);
                i1 = MathHelper.floor_double(v1.yCoord) - (enumfacing == EnumFacing.UP ? 1 : 0);
                j1 = MathHelper.floor_double(v1.zCoord) - (enumfacing == EnumFacing.SOUTH ? 1 : 0);
                IBlockState block1 = world.getBlockState(new BlockPos(l, i1, j1));
                if (!bool2 || block1.getBlock().getCollisionBoundingBox(block1, world, new BlockPos(l, i1, j1)) != null) {
                    if (block1.getBlock().canCollideCheck(block1, bool1)) {
                        RayTraceResult movingobjectposition1 = block1.getBlock().collisionRayTrace(block1, world, new BlockPos(l, i1, j1), v1, v2);
                        if (movingobjectposition1 != null) {
                            return movingobjectposition1;
                        }
                    } else {
                        movingobjectposition2 = new RayTraceResult(RayTraceResult.Type.MISS, v1, enumfacing, new BlockPos(l, i1, j1));
                    }
                }
            }
            return bool3 ? movingobjectposition2 : null;
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

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