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

The following are Jave code examples for showing how to use hasCapability() 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: Never-Enough-Currency   File: MessageSyncRemove.java   View Source Code Vote up 6 votes
@Override
public IMessage handleServerMessage(EntityPlayer player, MessageSyncRemove message, MessageContext ctx) {
	if ((player != null) && (message != null) && (ctx != null)) {
		EntityPlayer en = (EntityPlayer) player.getEntityWorld().getEntityByID(message.entityId);
		if (en != null) {
			if (player.getEntityId() == en.getEntityId() && en.getEntityWorld() != null && en.hasCapability(Currency.ACCOUNT_DATA, null)) {
				AccountCapability entityData = en.getCapability(Currency.ACCOUNT_DATA, null);
				for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
					if (player.inventory.getStackInSlot(i) != ItemStack.EMPTY && player.inventory.getStackInSlot(i).getItem() instanceof ItemMoneyBase) {
						player.inventory.setInventorySlotContents(i, ItemStack.EMPTY);
					}
				}
			}
		}
	}
	return null;
}
 
Example 2
Project: Never-Enough-Currency   File: MessageSyncClearList.java   View Source Code Vote up 6 votes
@Override
public IMessage handleServerMessage(EntityPlayer player, MessageSyncClearList message, MessageContext ctx) {
	if ((player != null) && (message != null) && (ctx != null)) {
		EntityPlayer en = (EntityPlayer) player.getEntityWorld().getEntityByID(message.entityId);
		if (en != null) {
			if (player.getEntityId() == en.getEntityId() && en.getEntityWorld() != null && en.hasCapability(Currency.CART_DATA, null)) {
				CartCapability entityData = en.getCapability(Currency.CART_DATA, null);

				entityData.setCart(NonNullList.withSize(entityData.getSizeInventory(), ItemStack.EMPTY), true);
				List<Float> prices = Arrays.asList(new Float[25]);
				for (int i = 0; i < prices.size(); i++) {
					prices.set(i, (float) 0);
				}
			}
		}
	}
	return null;
}
 
Example 3
Project: Bewitchment   File: EnergyEvents.java   View Source Code Vote up 5 votes
@SuppressWarnings("ConstantConditions")
@SubscribeEvent
public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
	final EntityPlayer oldPlayer = event.getOriginal();
	final EntityPlayer newPlayer = event.getEntityPlayer();

	if (event.isWasDeath() && oldPlayer.hasCapability(EnergyProvider.ENERGY_CAPABILITY, null) && newPlayer.hasCapability(EnergyProvider.ENERGY_CAPABILITY, null)) {
		final IEnergy oldCap = oldPlayer.getCapability(EnergyProvider.ENERGY_CAPABILITY, null);
		final IEnergy newCap = oldPlayer.getCapability(EnergyProvider.ENERGY_CAPABILITY, null);
		newCap.set(oldCap.get());
		newCap.setMax(oldCap.getMax());
		newCap.setRegen(oldCap.getRegenTime(), oldCap.getRegenBurst());
		newCap.setUses(oldCap.getUses());
	}
}
 
Example 4
Project: Bewitchment   File: EnergyHandler.java   View Source Code Vote up 5 votes
/**
 * Returns the {@link IEnergy} interface of the player.
 *
 * @param player The player
 * @return An {@link Optional<IEnergy>} for correctness
 */
@SuppressWarnings("ConstantConditions")
public static Optional<IEnergy> getEnergy(EntityPlayer player) {
	if (player.hasCapability(EnergyProvider.ENERGY_CAPABILITY, null)) {
		return Optional.of(player.getCapability(EnergyProvider.ENERGY_CAPABILITY, null));
	}
	return Optional.empty();
}
 
Example 5
Project: Game-Stages   File: PlayerDataHandler.java   View Source Code Vote up 2 votes
/**
 * Gets the stage data for a player.
 *
 * @param player The player to get stage data from.
 * @return The stage data for the player.
 */
public static IStageData getStageData (@Nonnull EntityPlayer player) {

    return player != null && player.hasCapability(CAPABILITY, EnumFacing.DOWN) ? player.getCapability(CAPABILITY, EnumFacing.DOWN) : null;
}