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

The following are Jave code examples for showing how to use getActiveHand() 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: Melodium   File: SongHorse.java   View Source Code Vote up 6 votes
@Override
public boolean songTick(EntityPlayer player, ItemStack instrument, int interval, int ticks, int length) {
	if (interval == 0 && ticks == 1) {
		EnumHand hand = player.getActiveHand();
		World world = player.world;
		SoundType t = SoundType.getSoundTypeByName(SoundType.AMBIENT.getTag());
		if (!world.isRemote) {
			EntityHorse horse = new EntityGhostHorse(world);
			horse.setHorseSaddled(true);
			horse.setTamedBy(player);
			horse.setLocationAndAngles(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
			world.spawnEntity(horse);
			player.startRiding(horse);
			NBTTagCompound tag = ItemUtil.getOrCreateTag(instrument);
			tag.setInteger("id", horse.getEntityId());
		}
		player.setActiveHand(hand);
	}
	return true;
}
 
Example 2
Project: AdvancedCombat   File: CustomShieldHandler.java   View Source Code Vote up 6 votes
/** Fixed vanilla code */
private void damageShield(EntityPlayer owner, float damage) {
	int i = 1 + MathHelper.floor(damage);
	owner.getActiveItemStack().damageItem(i, owner);

	if (owner.getActiveItemStack().getCount() <= 0) {
		EnumHand enumhand = owner.getActiveHand();
		ForgeEventFactory.onPlayerDestroyItem(owner, owner.getActiveItemStack(), enumhand);

		if(enumhand == EnumHand.MAIN_HAND) {
			owner.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
		} else {
			owner.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, ItemStack.EMPTY);
		}

		owner.resetActiveHand();
		owner.playSound(SoundEvents.ITEM_SHIELD_BREAK, 0.8F, 0.8F + owner.world.rand.nextFloat() * 0.4F);
	}
}
 
Example 3
Project: Got-Wood   File: BlockTreeTap.java   View Source Code Vote up 5 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,EntityPlayer playerIn, EnumHand hand, ItemStack heldItem,EnumFacing side, float hitX, float hitY, float hitZ) {
	super.onBlockActivated(worldIn, pos, state, playerIn, hand, heldItem,side, hitX, hitY, hitZ);
	if(worldIn.isRemote) {
	      return false;
	    }
	if(this.hasTileEntity(this.getDefaultState())){
		if(playerIn.getActiveHand() != null){
		ItemStack stack = playerIn.getHeldItem(playerIn.getActiveHand());
		if(stack != null){
			System.out.println("yep");
			if(stack.getItem() == Items.BUCKET){
				if(stack.stackSize > 0){
					--stack.stackSize;

					TileEntity te = worldIn.getTileEntity(pos);
					if(te instanceof TileTreeTap){
						((TileTreeTap)te).hasBucket = true;
						worldIn.setBlockState(pos, worldIn.getBlockState(pos).withProperty(HASBUCKET, true), 3);
						return true;
					}
				}
			}
		}
		}
	}
	return false;
}