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

The following are Jave code examples for showing how to use getPersistentID() 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: Bewitchment   File: TileEntityGlyph.java   View Source Code Vote up 4 votes
public void startRitual(EntityPlayer player) {
	if (player.getEntityWorld().isRemote)
		return;
	List<EntityItem> itemsOnGround = getWorld().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(getPos()).grow(3, 0, 3));
	List<ItemStack> recipe = itemsOnGround.stream().map(i -> i.getItem()).collect(Collectors.toList());
	for (Ritual rit : Ritual.REGISTRY) { // Check every ritual
		if (rit.isValidInput(recipe, hasCircles(rit))) { // Check if circles and items match
			if (rit.isValid(player, world, pos, recipe)) { // Checks of extra conditions are met
				if (consumePower(rit.getRequiredStartingPower())) { // Check if there is enough starting power (and uses it in case there is)
					// The following block saves all the item used in the input inside the nbt
					// vvvvvv
					this.ritualData = new NBTTagCompound();
					NBTTagList itemsUsed = new NBTTagList();
					itemsOnGround.forEach(ei -> {
						NBTTagCompound item = new NBTTagCompound();
						ei.getItem().writeToNBT(item);
						itemsUsed.appendTag(item);
						ei.setDead();
					});
					ritualData.setTag("itemsUsed", itemsUsed);
					// ^^^^^

					// Sets the ritual up
					this.ritual = rit;
					this.entityPlayer = player.getPersistentID();
					this.cooldown = 1;
					ritual.onStarted(player, this, getWorld(), getPos(), ritualData);
					player.sendStatusMessage(new TextComponentTranslation("ritual." + rit.getRegistryName().toString().replace(':', '.') + ".name", new Object[0]), true);
					world.notifyBlockUpdate(getPos(), world.getBlockState(getPos()), world.getBlockState(getPos()), 3);
					markDirty();
					return;
				} else {
					player.sendStatusMessage(new TextComponentTranslation("ritual.failure.power", new Object[0]), true);
					return;
				}
			} else {
				player.sendStatusMessage(new TextComponentTranslation("ritual.failure.precondition", new Object[0]), true);
				return;
			}

		}
	}
	if (!itemsOnGround.isEmpty())
		player.sendStatusMessage(new TextComponentTranslation("ritual.failure.unknown", new Object[0]), true);
}