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

The following examples show how to use net.minecraft.entity.player.EntityPlayer#getPrimaryHand() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: Cyberware   File: ItemHandUpgrade.java    License: MIT License 6 votes vote down vote up
@SubscribeEvent
public void handleMining(HarvestCheck event)
{
	EntityPlayer p = event.getEntityPlayer();
	ItemStack test = new ItemStack(this, 1, 2);
	boolean rightArm = (p.getPrimaryHand() == EnumHandSide.RIGHT ? 
			(CyberwareAPI.isCyberwareInstalled(p, new ItemStack(CyberwareContent.cyberlimbs, 1, 1))) : 
			(CyberwareAPI.isCyberwareInstalled(p, new ItemStack(CyberwareContent.cyberlimbs, 1, 0))));
	if (rightArm && CyberwareAPI.isCyberwareInstalled(p, test) && p.getHeldItemMainhand() == null)
	{
		ItemStack pick = new ItemStack(Items.STONE_PICKAXE);
		if (pick.canHarvestBlock(event.getTargetBlock()))
		{
			event.setCanHarvest(true);
		}
	}
}
 
Example 2
Source Project: Cyberware   File: ItemHandUpgrade.java    License: MIT License 5 votes vote down vote up
@SubscribeEvent
public void handleMineSpeed(BreakSpeed event)
{
	EntityPlayer p = event.getEntityPlayer();
	ItemStack test = new ItemStack(this, 1, 2);
	boolean rightArm = (p.getPrimaryHand() == EnumHandSide.RIGHT ? 
					(CyberwareAPI.isCyberwareInstalled(p, new ItemStack(CyberwareContent.cyberlimbs, 1, 1))) : 
					(CyberwareAPI.isCyberwareInstalled(p, new ItemStack(CyberwareContent.cyberlimbs, 1, 0))));
	if (rightArm && CyberwareAPI.isCyberwareInstalled(p, test) && p.getHeldItemMainhand() == null)
	{
		ItemStack pick = new ItemStack(Items.STONE_PICKAXE);
		event.setNewSpeed(event.getNewSpeed() * pick.getStrVsBlock(p.worldObj.getBlockState(event.getPos())));
	}
}
 
Example 3
Source Project: Cyberware   File: EssentialsMissingHandler.java    License: MIT License 5 votes vote down vote up
private void processEvent(Event event, EnumHand hand, EntityPlayer p, ICyberwareUserData cyberware)
{
	EnumHandSide mainHand = p.getPrimaryHand();
	EnumHandSide offHand = ((mainHand == EnumHandSide.LEFT) ? EnumHandSide.RIGHT : EnumHandSide.LEFT);
	EnumSide correspondingMainHand = ((mainHand == EnumHandSide.RIGHT) ? EnumSide.RIGHT : EnumSide.LEFT);
	EnumSide correspondingOffHand = ((offHand == EnumHandSide.RIGHT) ? EnumSide.RIGHT : EnumSide.LEFT);
	
	boolean leftUnpowered = false;
	ItemStack armLeft = cyberware.getCyberware(new ItemStack(CyberwareContent.cyberlimbs, 1, 0));
	if (armLeft != null && !ItemCyberlimb.isPowered(armLeft))
	{
		leftUnpowered = true;
	}
	
	boolean rightUnpowered = false;
	ItemStack armRight = cyberware.getCyberware(new ItemStack(CyberwareContent.cyberlimbs, 1, 1));
	if (armRight != null && !ItemCyberlimb.isPowered(armRight))
	{
		rightUnpowered = true;
	}

	if (hand == EnumHand.MAIN_HAND && (!cyberware.hasEssential(EnumSlot.ARM, correspondingMainHand) || leftUnpowered))
	{
		event.setCanceled(true);
	}
	else if (hand == EnumHand.OFF_HAND && (!cyberware.hasEssential(EnumSlot.ARM, correspondingOffHand) || rightUnpowered))
	{
		event.setCanceled(true);
	}
}