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

The following are Jave code examples for showing how to use getPosition() 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: minecraft-hue   File: EventListener.java   View Source Code Vote up 6 votes
@SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
    if (!(event.getEntity() instanceof EntityPlayer)) {
        return;
    }
    EntityPlayer player = (EntityPlayer) event.getEntity();
    if (player.isDead) {
        this.hueManager.adjustColor(new Color(255, 0, 0));
        return;
    }
    BlockPos pos = player.getPosition();
    Chunk chunk = this.world.getChunkFromBlockCoords(pos);
    Biome biome = chunk.getBiome(pos, this.world.getBiomeProvider());
    String color = this.biomeMap.get(biome.getRegistryName().getResourcePath());
    if (color != null) {
        this.hueManager.adjustColor(color);
    }
}
 
Example 2
Project: Infernum   File: SpellSoulDrain.java   View Source Code Vote up 6 votes
@Override
public void onCastTick(World world, EntityPlayer player, ItemStack stack) {
	if (!world.isRemote) {
		BlockPos centerPos = player.getPosition();
		AxisAlignedBB area = new AxisAlignedBB(centerPos).expandXyz(3F);
		for (Entity entity : world.getEntitiesWithinAABBExcludingEntity(player, area)) {
			if (entity instanceof EntityLivingBase) {
				WorldServer worldServer = (WorldServer) world;
				if (player.getItemInUseCount() % 10 == 0 && consumePower(player)) {
					MessageSoulDrainFX message = new MessageSoulDrainFX(entity.posX,
							entity.posY + (entity.height / 2.0F), entity.posZ, player.posX,
							player.posY + (player.height / 2.0F), player.posZ);
					PacketHandler.INSTANCE.sendToAllAround(message, new NetworkRegistry.TargetPoint(
							player.dimension, player.posX, player.posY, player.posZ, 128));
					entity.attackEntityFrom(DamageSource.magic, 1);
					world.spawnEntity(new EntityXPOrb(world, entity.posX, entity.posY + 0.5, entity.posZ, 1));
				}
			}
		}
	}
}
 
Example 3
Project: uniquecrops   File: ItemEnderSnooker.java   View Source Code Vote up 6 votes
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
	
	List<EntityLivingBase> elb = acquireAllLookTargets(player, 32, 3);
	for (EntityLivingBase target : elb) {
		if (target.canEntityBeSeen(player) && !(target instanceof EntityPlayer)) {
			BlockPos targetpos = target.getPosition();
			BlockPos playerpos = player.getPosition();
			if (!world.isRemote) {
				target.setPositionAndUpdate(playerpos.getX(), playerpos.getY(), playerpos.getZ());
				player.setPositionAndUpdate(targetpos.getX(), targetpos.getY(), targetpos.getZ());
				if (target instanceof EntityWolf && world.rand.nextInt(100) == 0)
					target.entityDropItem(UCItems.generic.createStack(EnumItems.DOGRESIDUE), 1);
				stack.damageItem(1, player);
				return new ActionResult(EnumActionResult.SUCCESS, stack);
			}
		}
	}
	return new ActionResult(EnumActionResult.PASS, stack);
}
 
Example 4
Project: MineCamera   File: ItemPictureBook.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn,
		EnumHand hand) {
	playerIn.setActiveHand(hand);
	if (!worldIn.isRemote) {
		BlockPos pos = playerIn.getPosition();
		int id = GuiElementLoader.GUI_PICTURE_BOOK;
		playerIn.openGui(MineCamera.instance, id, worldIn, pos.getX(), pos.getY(), pos.getZ());
	}
	return new ActionResult(EnumActionResult.SUCCESS, itemStackIn);
}
 
Example 5
Project: pnc-repressurized   File: CamoTECache.java   View Source Code Vote up 5 votes
static Set<BlockPos> getCamouflageableBlockPos(World worldIn, EntityPlayer entityIn) {
    if (worldIn == null) return Collections.emptySet();

    if (lastPlayerPos == null || teSet == null || entityIn.getDistanceSq(lastPlayerPos) > 9) {
        lastPlayerPos = entityIn.getPosition();
        teSet = worldIn.loadedTileEntityList.stream()
                .filter(te -> te instanceof ICamouflageableTE && te.getPos().distanceSq(entityIn.posX, entityIn.posY, entityIn.posZ) < 144
                )
                .map(TileEntity::getPos)
                .collect(Collectors.toSet());
    }
    return teSet;
}
 
Example 6
Project: Industrial-Foregoing   File: BookManualItem.java   View Source Code Vote up 5 votes
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
    BlockPos pos = playerIn.getPosition();
    if (playerIn.isSneaking()) {
        RayTraceResult result = rayTrace(worldIn, playerIn, false);
        if (result != null && result.typeOfHit == RayTraceResult.Type.BLOCK) {
            pos = result.getBlockPos();
        }
    }
    playerIn.openGui(IndustrialForegoing.instance, GuiHandler.BOOK, worldIn, pos.getX(), pos.getY(), pos.getZ());
    return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
}
 
Example 7
Project: MeeCreeps   File: ClientActionManager.java   View Source Code Vote up 5 votes
public static void showProblem(String message, String... parameters) {
    EntityPlayer player = MeeCreeps.proxy.getClientPlayer();
    World worldIn = MeeCreeps.proxy.getClientWorld();
    BlockPos pos = player.getPosition();
    String translated = I18n.format(message, parameters);
    BalloonRenderer.addMessage(translated);
}
 
Example 8
Project: MeeCreeps   File: WorkerHelper.java   View Source Code Vote up 5 votes
public static BlockPos findSuitablePositionNearPlayer(@Nonnull EntityMeeCreeps meeCreep, @Nonnull EntityPlayer player, double distance) {
    Vec3d playerPos = player.getPositionVector();
    Vec3d entityPos = meeCreep.getPositionVector();

    if (entityPos.distanceTo(playerPos) < (distance * 1.2)) {
        // No need to move
        return meeCreep.getPosition();
    }

    double dx = playerPos.x - entityPos.x;
    double dy = playerPos.x - entityPos.x;
    double dz = playerPos.x - entityPos.x;
    Vec3d v = new Vec3d(-dx, -dy, -dz);
    v = v.normalize();
    Vec3d pos = new Vec3d(playerPos.x + v.x * distance, playerPos.y + v.y * distance, playerPos.z + v.z * distance);
    // First find a good spot at the specific location
    World world = player.getEntityWorld();

    float width = meeCreep.width;
    float eyeHeight = meeCreep.getEyeHeight();

    // First try on the prefered spot
    BlockPos p = scanSuitablePos(new BlockPos(pos.x, pos.y + .5, pos.z), world, width, eyeHeight);
    if (p != null) return p;
    // No good spot to stand on found. Try other spots around the prefered spot
    p = scanAround(pos, world, width, eyeHeight);
    if (p != null) return p;
    // No good spot to stand on found. Try other spots around the player
    p = scanAround(playerPos, world, width, eyeHeight);
    if (p != null) return p;

    // If all else fails we go stand where the player is
    return player.getPosition();
}
 
Example 9
Project: VirtualTool   File: VirtualEnchantingTable.java   View Source Code Vote up 5 votes
public VirtualEnchantingTable(EntityPlayer entityHuman, float power) {
    super(entityHuman.inventory, entityHuman.world, entityHuman.getPosition());
    this.worldPointer = entityHuman.world;
    this.position = entityHuman.getPosition();
    this.rand = new Random();
    this.entityHumans = entityHuman;
    this.power = power;
}
 
Example 10
Project: MeeCreeps   File: FollowAndPickupActionWorker.java   View Source Code Vote up 4 votes
@Override
public void tick(boolean timeToWrapUp) {
    IMeeCreep entity = helper.getMeeCreep();
    EntityMeeCreeps meeCreep = (EntityMeeCreeps) entity;
    EntityPlayer player = options.getPlayer();

    if (timeToWrapUp) {
        helper.done();
    } else if (player == null) {
        helper.taskIsDone();
    } else if (player.getEntityWorld().provider.getDimension() != meeCreep.getEntityWorld().provider.getDimension()) {
        // Wrong dimension, do nothing as this is handled by ServerActionManager
    } else {
        BlockPos position = player.getPosition();
        AxisAlignedBB box = new AxisAlignedBB(position.add(-6, -4, -6), position.add(6, 4, 6));
        List<EntityItem> items = entity.getWorld().getEntitiesWithinAABB(EntityItem.class, box, input -> {
            if (!input.getItem().isEmpty()) {
                if (input.getItem().getItem() instanceof ItemBlock) {
                    if (DigTunnelActionWorker.isNotInterestedIn(((ItemBlock) input.getItem().getItem()).getBlock())) {
                        return false;
                    }
                }
            }
            return true;
        });
        if (!items.isEmpty()) {
            items.sort((o1, o2) -> {
                double d1 = position.distanceSq(o1.posX, o1.posY, o1.posZ);
                double d2 = position.distanceSq(o2.posX, o2.posY, o2.posZ);
                return Double.compare(d1, d2);
            });
            EntityItem entityItem = items.get(0);
            helper.navigateTo(entityItem, (pos) -> helper.pickup(entityItem));
        } else if (entity.hasStuffInInventory()) {
            helper.navigateTo(helper.findSuitablePositionNearPlayer(1.0), blockPos -> helper.giveToPlayerOrDrop());
        } else {
            // Find a spot close to the player where we can navigate too
            BlockPos p = helper.findSuitablePositionNearPlayer(4.0);
            helper.navigateTo(p, blockPos -> {});
        }
    }
}
 
Example 11
Project: VirtualTool   File: VirtualAnvil.java   View Source Code Vote up 4 votes
public VirtualAnvil(EntityPlayer entityHuman) {
    this(entityHuman, entityHuman.getPosition());
}
 
Example 12
Project: VirtualTool   File: VirtualWorkbench.java   View Source Code Vote up 4 votes
public VirtualWorkbench(EntityPlayer entityHuman) {
    super(entityHuman.inventory, entityHuman.world, entityHuman.getPosition());
}
 
Example 13
Project: PacketControl   File: PacketControlFactory.java   View Source Code Vote up 4 votes
public static PacketUseBed createUseBed(Player player) {
    EntityPlayer p = (EntityPlayer)player;

    return (PacketUseBed)new SPacketUseBed(p, p.getPosition());
}
 
Example 14
Project: WirelessCharger   File: TileWirelessCharger.java   View Source Code Vote up 3 votes
private double outputByRange(EntityPlayer player, double energy, BlockPos pos) {

        BlockPos playerPos = player.getPosition();
        double distance = Math.floor(pos.getDistance(playerPos.getX(), playerPos.getY(), playerPos.getZ()));

        return (energy / (1D + (Config.wirelessRangeEnergyRate / 1000D) * distance));
    }
 
Example 15
Project: WirelessCharger   File: TileWirelessCharger.java   View Source Code Vote up 3 votes
private double costByRange(EntityPlayer player, double cost, BlockPos pos) {

        BlockPos playerPos = player.getPosition();
        double distance = Math.floor(pos.getDistance(playerPos.getX(), playerPos.getY(), playerPos.getZ()));

        return (cost * (1D + (Config.wirelessRangeEnergyRate / 1000D) * distance));
    }
 
Example 16
Project: WirelessCharger   File: TilePersonalCharger.java   View Source Code Vote up 3 votes
private double outputByRange(EntityPlayer player, double energy, BlockPos pos) {

        BlockPos playerPos = player.getPosition();
        double distance = Math.floor(pos.getDistance(playerPos.getX(), playerPos.getY(), playerPos.getZ()));

        return (energy / (1D + (Config.rangeRate / 1000D) * Math.max(1, distance / 100D)));
    }
 
Example 17
Project: WirelessCharger   File: TilePersonalCharger.java   View Source Code Vote up 3 votes
private double costByRange(EntityPlayer player, double cost, BlockPos pos) {

        BlockPos playerPos = player.getPosition();
        double distance = Math.floor(pos.getDistance(playerPos.getX(), playerPos.getY(), playerPos.getZ()));

        return (cost * (1D + (Config.rangeRate / 1000D) * Math.max(1, distance / 100D)));
    }