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

The following are Jave code examples for showing how to use getDistance() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Metalworks   File: TileBase.java   View Source Code Vote up 6 votes
public void syncToClients(){
    if(this.world != null && !this.world.isRemote){
        if(world.getTotalWorldTime() % 10 == 0){
            NBTTagCompound syncTag = new NBTTagCompound();
            this.writeNBT(syncTag, NBTType.SYNC);
            for(EntityPlayer player : this.world.playerEntities){
                if(player instanceof EntityPlayerMP && player.getDistance(pos.getX(), pos.getY(), pos.getZ()) <= 64){
                    NetworkHandler.NET.sendTo(new PacketSyncTile(syncTag, this.pos), (EntityPlayerMP) player);
                }
            }
            this.isSyncDirty = false;
        } else {
            this.isSyncDirty = true;
        }
    }
}
 
Example 2
Project: creativezone   File: CreativeZoneMod.java   View Source Code Vote up 6 votes
@SubscribeEvent
public void onWorldTick(TickEvent.WorldTickEvent e) {
    if (!e.world.isRemote && e.phase == TickEvent.Phase.START && e.world.provider.getDimension() == 0) {
        long now = Instant.now().getEpochSecond();
        if (now - lastCheck > checkInterval) {
            BlockPos spawn = e.world.getSpawnPoint();
            for (int i = 0; i < e.world.playerEntities.size(); i++)
            {
                EntityPlayer p = e.world.playerEntities.get(i);
                // If the user is inside the zone radius, force them back to creative
                if (p.getDistance(spawn.getX(), p.posY, spawn.getZ()) < zoneRadius) {
                    p.setGameType(GameType.CREATIVE);
                } else {
                    // Otherwise, the user is outside the radius and we need to force
                    // them back to survival (assuming they're not on the whitelist)
                    if (!whitelist.contains(p.getName())) {
                        p.setGameType(GameType.SURVIVAL);
                    }
                }
            }
            lastCheck = now;
        }
    }
}
 
Example 3
Project: ThaumOres   File: BlockInfusedBlockOre.java   View Source Code Vote up 5 votes
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) {
	double viewDistance = 0D;
	double currentDistance = player.getDistance(x + 0.5D, y + 0.5D, z + 0.5D);
	boolean hasVisualAcuity = false;
	boolean hasWarpVisualAcuity = false;
	boolean canView = false;
	if (player != null) {
		hasVisualAcuity = ThaumUtils.isComplete(player, TOThaum.riVisualAcuity);
		hasWarpVisualAcuity = ThaumUtils.isComplete(player, TOThaum.riWarpVisualAcuity);
		if ((player.inventory.armorItemInSlot(3) != null)
				&& (player.inventory.armorItemInSlot(3).getItem() instanceof IRevealer)
				&& (((IRevealer) player.inventory.armorItemInSlot(3).getItem())
						.showNodes(player.inventory.armorItemInSlot(3), player))) {
			canView = true;
			viewDistance = hasVisualAcuity ? 32.0D : 16.0D;
		} else if ((player.inventory.getCurrentItem() != null)
				&& (player.inventory.getCurrentItem().getItem() instanceof ItemThaumometer)
				&& (UtilsFX.isVisibleTo(0.44F, player, x, y, z))) {
			canView = true;
			viewDistance = hasVisualAcuity ? 16.0D : 8.0D;
		}
		if (hasWarpVisualAcuity) {
			int warp = ThaumUtils.getWarp(player);
			canView = true;
			double warpViewDistance = warp * TOConfig.generalWarpVisualAcuityModifier;
			if (warpViewDistance > viewDistance)
				viewDistance = warpViewDistance;
		}
	}
	if (canView && currentDistance <= viewDistance) {
		return new ItemStack(this, 1, world.getBlockMetadata(x, y, z));
	} else
		return new ItemStack(baseBlock, 1, baseMeta);
}