Java Code Examples for net.minecraft.entity.player.EntityPlayer#getDistanceSqToEntity()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#getDistanceSqToEntity() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public boolean loadOrRender(EntityPlayer player) {
    for (PotionEffect effect : player.getActivePotionEffects()) {
        if (effect.getPotionID() == 14) return false;
    }

    if (!renderFromTeam(player) || player.riddenByEntity != null) {
        return false;
    }

    int renderDistance = Levelhead.getInstance().getDisplayManager().getMasterConfig().getRenderDistance();
    int min = Math.min(64 * 64, renderDistance * renderDistance);
    return !(player.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) > min) &&
        (!player.hasCustomName() || !player.getCustomNameTag().isEmpty()) &&
        !player.getDisplayName().toString().isEmpty() &&
        existedMoreThan5Seconds.contains(player.getUniqueID()) &&
        !player.getDisplayName().getFormattedText().contains(ChatColor.COLOR_CHAR + "k") &&
        !player.isInvisible() &&
        !player.isInvisibleToPlayer(Minecraft.getMinecraft().thePlayer) &&
        !player.isSneaking();
}
 
Example 2
@SideOnly(Side.CLIENT)
public static void processBoltPacket(PacketFamiliarBolt pkt) {
    EntityPlayer p = Minecraft.getMinecraft().theWorld.getPlayerEntityByName(pkt.owner);
    if(p == null || p.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) > 1024) return; //32^2
    ExFamiliarData data = clientFamiliars.get(p.getCommandSenderName());
    if(data == null) return;
    PartialEntityFamiliar fam = data.familiar;
    float y = (float) (fam.posY + 1.22F);
    if (!Minecraft.getMinecraft().thePlayer.getCommandSenderName().equalsIgnoreCase(pkt.owner)) {
        y += 0.2F;
    }
    FXLightningBolt bolt = new FXLightningBolt(Minecraft.getMinecraft().theWorld, (float) fam.posX, y, (float) fam.posZ, pkt.targetX, pkt.targetY, pkt.targetZ, Minecraft.getMinecraft().theWorld.rand.nextLong(), 10, 4.0F, 5);
    bolt.defaultFractal();
    bolt.setType(pkt.type);
    bolt.finalizeBolt();
}
 
Example 3
Source Project: archimedes-ships   File: ShipHandlerClient.java    License: MIT License 5 votes vote down vote up
@Override
public boolean interact(EntityPlayer player)
{
	if (player.getDistanceSqToEntity(ship) >= 36D)
	{
		MsgFarInteract msg = new MsgFarInteract(ship);
		ArchimedesShipMod.instance.pipeline.sendToServer(msg);
	}
	
	return super.interact(player);
}
 
Example 4
public static double getDistanceSqToNearestPlayer(Entity entity, double maxRange) {
  AxisAlignedBB bounds = getBoundsAround(entity, maxRange);
  EntityPlayer nearest = (EntityPlayer) entity.getEntityWorld().findNearestEntityWithinAABB(EntityPlayer.class, bounds, entity);
  if (nearest == null) {
    return 1;
  }
  return nearest.getDistanceSqToEntity(entity);
}
 
Example 5
@InvokeEvent
public void render(RenderPlayerEvent event) {
    if (levelhead == null ||
        levelhead.getDisplayManager() == null ||
        levelhead.getDisplayManager().getMasterConfig() == null ||
        !levelhead.getDisplayManager().getMasterConfig().isEnabled()) {
        return;
    }

    EntityPlayer player = event.getEntity();
    int o = 0;

    for (AboveHeadDisplay display : levelhead.getDisplayManager().getAboveHead()) {
        int index = display.getIndex();
        int extraHead = levelhead.getLevelheadPurchaseStates().getExtraHead();
        if (index > extraHead || !display.getConfig().isEnabled()) continue;

        LevelheadTag levelheadTag = display.getCache().get(player.getUniqueID());

        if (display.loadOrRender(player) && levelheadTag != null && !(levelheadTag instanceof NullLevelheadTag)) {
            if ((event.getEntity().getUniqueID().equals(Levelhead.getInstance().userUuid) && !display.getConfig().isShowSelf()
                || !Hyperium.INSTANCE.getHandlers().getHypixelDetector().isHypixel())) {
                continue;
            }

            if (player.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) < 64 * 64) {
                double offset = 0.3;
                Scoreboard scoreboard = player.getWorldScoreboard();
                ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(2);

                if (objective != null && event.getEntity().getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) < 10 * 10) {
                    offset *= 2;
                }

                if (player.getUniqueID().equals(levelhead.userUuid) && !Settings.SHOW_OWN_NAME) offset -= .3;
                if (Hyperium.INSTANCE.getCosmetics().getDeadmau5Cosmetic().isPurchasedBy(event.getEntity().getUniqueID())) {
                    HyperiumPurchase packageIfReady = PurchaseApi.getInstance().getPackageIfReady(event.getEntity().getUniqueID());
                    if (packageIfReady != null) {
                        AbstractHyperiumPurchase purchase = packageIfReady.getPurchase(EnumPurchaseType.DEADMAU5_COSMETIC);
                        if (purchase != null) {
                            if (event.getEntity().getUniqueID() != Minecraft.getMinecraft().thePlayer.getUniqueID()) {
                                if (((EarsCosmetic) purchase).isEnabled()) {
                                    offset += .3;
                                }
                            } else if (Settings.EARS_STATE.equalsIgnoreCase("on")) {
                                offset += .2;
                            }
                        }
                    }
                }

                offset += levelhead.getDisplayManager().getMasterConfig().getOffset();
                renderName(event, levelheadTag, player, event.getX(), event.getY() + offset + o * .3D, event.getZ());
            }
        }

        o++;
    }
}