Java Code Examples for net.minecraft.entity.Entity#getPosition()

The following examples show how to use net.minecraft.entity.Entity#getPosition() . 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
Source File: LexWand.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void onAltarAction(World world, BlockPos pos) {
	List<Entity> entities = world.getEntitiesWithinAABB(EntityLivingBase.class, AOE.offset(pos));
	if (entities.isEmpty()) return;
		
	Entity entity = entities.get(world.rand.nextInt(entities.size()));
	
	world.getEntitiesWithinAABB(EntityPlayer.class, AOE.grow(6).offset(pos)).forEach((player) -> {
		player.sendMessage(new TextComponentString(getBanMsg(entity, world.rand)));
	});
	
	BlockPos entityPos = entity.getPosition();
	world.addWeatherEffect(new EntityLightningBolt(world, entityPos.getX(), entityPos.getY(), entityPos.getZ(), false));
}
 
Example 2
Source File: BlockFluidLethe.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
	public static void onEntityUpdate(EntityUpdateEvent event) {
		Entity entityIn = event.getEntity();
		BlockPos pos = entityIn.getPosition();
		World world = entityIn.world;
		IBlockState state = world.getBlockState(pos);
//		if (state.getBlock() == ModFluids.LETHE.getActualBlock()) {
//
//			run(world, pos, state.getBlock(), entityIn,
//					entity -> entity instanceof EntityPlayer,
//					entity -> {
//						EntityPlayer player = (EntityPlayer) entity;
//						if (player.experienceLevel > 0)
//							CapManager.forObject(player).addMana(expToNextLevel(--player.experienceLevel));
//					});
//
//		}

		run(world, pos, state.getBlock(), entityIn,
				entity -> entity instanceof EntityItem && ManaRecipes.RECIPES.keySet().stream().anyMatch(item -> item.apply(((EntityItem) entity).getItem())),
				entity -> {
					List<Map.Entry<Ingredient, FluidRecipeLoader.FluidCrafter>> allEntries = ManaRecipes.RECIPES.entries().stream().filter(entry ->
							entry.getValue().getFluid().getBlock() == state.getBlock() &&
									entry.getKey().apply(((EntityItem) entity).getItem())).collect(Collectors.toList());
					allEntries.forEach(crafter -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), crafter.getValue().build()));
				});
	}
 
Example 3
Source File: Nyan.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
private static void updateNyanEntity(MinecraftServer server, WorldServer world, Entity entity,
		NBTTagCompound data) {
	Entity nyanEntity = null;

	if(data.hasUniqueId(NYAN_ENTITY_UUID_KEY)) {
		nyanEntity = server.getEntityFromUuid(data.getUniqueId(NYAN_ENTITY_UUID_KEY));
	}

	boolean shouldSpawn = false;

	if(nyanEntity == null || nyanEntity.isDead) {
		nyanEntity = newNyanEntity(world);
		nyanEntity.getEntityData().setUniqueId(NYANED_ENTITY_UUID_KEY, entity.getUniqueID());
		data.setUniqueId(NYAN_ENTITY_UUID_KEY, nyanEntity.getUniqueID());
		shouldSpawn = true;
	}

	final BlockPos entityPos = entity.getPosition();
	double entityHeightMultiplier = world.getTotalWorldTime() % 2 == 0 ? 3.5 : 4.0;

	//Account for dab particles
	if(entity instanceof EntityPlayer) {
		entityHeightMultiplier += 2.0;
	}

	//I *could* disable the AI, but this is more fun
	nyanEntity.setPositionAndRotation(
			entityPos.getX(),
			entityPos.getY() + entity.height * entityHeightMultiplier + nyanEntity.height,
			entityPos.getZ(),
			entity.rotationYaw,
			entity.rotationPitch
	);
	nyanEntity.setRotationYawHead(entity.getRotationYawHead());
	nyanEntity.setEntityInvulnerable(true);

	if(shouldSpawn) {
		world.spawnEntity(nyanEntity);
	}

	final BlockPos nyanPos = nyanEntity.getPosition();
	final NyanDirection direction =
			NyanDirection.getDirectionFacing(nyanEntity, Rotation.CLOCKWISE_90);

	world.spawnParticle(
			//Wool
			EnumParticleTypes.REDSTONE,
			//Not long distance
			false,
			nyanPos.getX() + direction.getXDirection() * 12.0,
			nyanPos.getY() - 2.5,
			nyanPos.getZ() + direction.getZDirection() * 12.0,
			//Number of particles
			10,
			direction.getXDirection() * 5.0,
			0.0,
			direction.getZDirection() * 5.0,
			//Speed
			10.0
	);
}
 
Example 4
Source File: BlockFluidMana.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public static void onEntityUpdate(EntityUpdateEvent event) {
	Entity entityIn = event.getEntity();
	BlockPos pos = entityIn.getPosition();
	World world = entityIn.world;
	IBlockState state = world.getBlockState(pos);
	if (state.getBlock() == ModFluids.MANA.getActualBlock()) {
		// Fizz all entities in the pool
		if (world.isRemote)
			run(world, pos, state.getBlock(), entityIn,
				entity -> true,
				entity -> LibParticles.FIZZING_AMBIENT(world, entityIn.getPositionVector()));

		// Nullify gravity of player
		if (!world.isRemote)
			run(world, pos, state.getBlock(), entityIn,
					entity -> entity instanceof EntityLivingBase,
					entity -> {
						((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 100, 0, true, false));
						if (RandUtil.nextInt(50) == 0) entity.attackEntityFrom(DamageSourceMana.INSTANCE, 0.1f);
					});

		run(world, pos, state.getBlock(), entityIn,
				entity -> entity instanceof EntityLivingBase,
				entity -> entityIn.motionY += 0.003);


		// Subtract player food
		run(world, pos, state.getBlock(), entityIn,
				entity -> entity instanceof EntityPlayer,
				entity -> {

					if (!world.isRemote) {
						MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
						Advancement advancement = server.getAdvancementManager().getAdvancement(new ResourceLocation(Wizardry.MODID, "advancements/advancement_crunch.json"));
						if (advancement == null) return;
						AdvancementProgress progress = ((EntityPlayerMP) entity).getAdvancements().getProgress(advancement);
						for (String s : progress.getRemaningCriteria()) {
							((EntityPlayerMP) entity).getAdvancements().grantCriterion(advancement, s);
						}
					}
					if (!((EntityPlayer) entity).capabilities.isCreativeMode && RandUtil.nextInt(50) == 0)
						((EntityPlayer) entity).getFoodStats().addExhaustion(1f);
				});
		// Explode explodable items
		run(world, pos, state.getBlock(), entityIn,
				entity -> entity instanceof EntityItem && ((EntityItem) entity).getItem().getItem() instanceof IPotionEffectExplodable,
				entity -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), new ManaRecipes.ExplodableCrafter()));
	}


	run(world, pos, state.getBlock(), entityIn,
			entity -> entity instanceof EntityItem && ManaRecipes.RECIPES.keySet().stream().anyMatch(item -> item.apply(((EntityItem) entity).getItem())),
			entity -> {
				List<Map.Entry<Ingredient, FluidRecipeLoader.FluidCrafter>> allEntries = ManaRecipes.RECIPES.entries().stream().filter(entry ->
						entry.getValue().getFluid().getBlock() == state.getBlock() &&
								entry.getKey().apply(((EntityItem) entity).getItem())).collect(Collectors.toList());
				allEntries.forEach(crafter -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), crafter.getValue().build()));
			});
}
 
Example 5
Source File: PlatformCommand.java    From YUNoMakeGoodMap with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
        throw new WrongUsageException(getUsage(sender));

    String cmd = args[0].toLowerCase(Locale.ENGLISH);
    if ("list".equals(cmd))
    {
        sender.sendMessage(new TextComponentString("Known Platforms:"));
        for (ResourceLocation rl : getPlatforms())
        {
            sender.sendMessage(new TextComponentString("  " + rl.toString()));
        }
    }
    else if ("spawn".equals(cmd) || "preview".equals(cmd))
    {
        if (args.length < 2)
            throw new WrongUsageException(getUsage(sender));

        Entity ent = sender.getCommandSenderEntity();
        PlacementSettings settings = new PlacementSettings();
        WorldServer world = (WorldServer)sender.getEntityWorld();

        if (args.length >= 3)
        {
            //TODO: Preview doesnt quite work correctly with rotations....
            String rot = args[2].toLowerCase(Locale.ENGLISH);
            if ("0".equals(rot) || "none".equals(rot))
                settings.setRotation(Rotation.NONE);
            else if ("90".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_90);
            else if ("180".equals(rot))
                settings.setRotation(Rotation.CLOCKWISE_180);
            else if ("270".equals(rot))
                settings.setRotation(Rotation.COUNTERCLOCKWISE_90);
            else
                throw new WrongUsageException("Only rotations none, 0, 90, 180, and 270 allowed.");
        }

        BlockPos pos;
        if (args.length >= 6)
            pos = CommandBase.parseBlockPos(sender, args, 3, false);
        else if (ent != null)
            pos = ent.getPosition();
        else
            throw new WrongUsageException("Must specify a position if the command sender is not an entity");

        Template temp = StructureUtil.loadTemplate(new ResourceLocation(args[1]), world, true);

        BlockPos spawn = StructureUtil.findSpawn(temp, settings);
        if (spawn != null)
            pos = pos.subtract(spawn);

        if ("spawn".equals(cmd))
        {
            sender.sendMessage(new TextComponentString("Building \"" + args[1] +"\" at " + pos.toString()));
            temp.addBlocksToWorld(world, pos, settings, 2); //Push to world, with no neighbor notifications!
            world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!
        }
        else
        {
            BlockPos tpos = pos.down();
            if (spawn != null)
                tpos = tpos.add(spawn);
            sender.sendMessage(new TextComponentString("Previewing \"" + args[1] +"\" at " + pos.toString()));
            world.setBlockState(tpos, Blocks.STRUCTURE_BLOCK.getDefaultState().withProperty(BlockStructure.MODE, TileEntityStructure.Mode.LOAD));
            TileEntityStructure te = (TileEntityStructure)world.getTileEntity(tpos);
            if (spawn != null)
                te.setPosition(te.getPosition().subtract(spawn));
            te.setSize(temp.getSize());
            te.setMode(Mode.LOAD);
            te.markDirty();
        }
    }
    else
        throw new WrongUsageException(getUsage(sender));
}